The Yankees scratched out their ninth-inning run without getting the ball out of the infield and Mariano Rivera came on in the bottom half of the inning to earn his 12th save.
New York had lost its previous two games.
The contest had been tied at 2-2 since the second inning when Wells opened the ninth with an infield single off Rafael Betancourt (1-1).
Wells stole second and after Lyle Overbay drew a walk, after which both runners moved up on a sacrifice from Ichiro Suzuki. Jayson Nix was intentionally walked to load the bases and Travis Hafner struck out, bringing up Boesch as a pinch-hitter for pitcher David Robertson.
Boesch's infield hit made a winner out of Robertson (2-0), who worked the bottom of the eighth.