BALTIMORE — Mike Carp and Jonny Gomes homered to back an effective pitching performance by John Lackey, and the Boston Red Sox beat the Orioles 5-4 Saturday to end a five-game losing streak in Baltimore.

After dropping the first two games of the series, the Red Sox fell into an early 2-0 hole before bouncing back. Carp's home run snapped an 18-inning scoring drought in the fourth, and Gomes made it 5-2 in the sixth with a solo shot that chased Baltimore starter Freddy Garcia (3-4).

The victory increased Boston's lead over second-place Baltimore in the AL East to 2½ games. The Red Sox lost three games at Camden Yards last September and were 0-2 this season, their longest dry spell in Baltimore since a seven-game stretch in 1969-70.

Lackey (4-5) gave up two runs, seven hits and a walk in seven innings to improve to 12-4 lifetime against the Orioles. It was the right-hander's first win since May 25, even though he's allowed three runs or fewer in nine of his 11 starts this season.

Former Oriole Koji Uehara struck out the side in the eighth and Andrew Bailey gave up a two-run homer to Matt Wieters in the ninth before securing his eighth save.

The game ended when pinch-runner Alexi Casilla took off from first base on a one-out liner to right by Ryan Flaherty. Shane Victorino made the catch without much difficulty and threw out Casilla for the double play.

Baltimore's Manny Machado extended his career-high hitting streak to 13 games and hit his major-league leading 31st double. Despite the loss, Baltimore has won 13 of its last 18 games against the Red Sox.

The Orioles took a 2-0 lead before Lackey got an out. After Nate McLouth singled off the pitcher's foot and scored on a double by Machado, Nick Markakis singled and Adam Jones drove in a run with an infield hit. Lackey avoided further damage by retiring Wieters and J.J. Hardy with runners at second and third.

David Ortiz led off the Boston second inning with a liner to center that bounced off the wall and eluded Jones. The husky man known as "Big Papi" legged it out for his second triple this month; the last time Ortiz had two triples in a season was 2006.

With Ortiz on third, Carp drew a walk before Garcia got three straight outs.

The Red Sox ended their season-high scoring drought with a three-run fourth. After Dustin Pedroia singled and Carp homered to tie it, Gomes singled and Stephen Drew ended a 4-for-31 skid with an RBI double.

Carp has been playing recently in place of Mike Napoli, who was sent back to Boston to determine the nature of an illness that has kept him sidelined since the third inning of Thursday's game.

Boston made it 4-2 in the fifth. Jacoby Ellsbury led off with a single, his first hit in 12 at-bats during this series. He stole second, advanced on a bunt and scored on Pedroia's grounder to shortstop.

Baltimore put runners at the corners with no outs in the bottom half, but Lackey worked out of the jam. The threat began with an infield hit by Taylor Teagarden, who was 0 for 21 this season before that at-bat.

NOTES: Red Sox rookie Jose Iglesias stretched his hitting streak to 16 games, longest by a Boston player this season. ... At the request of Jones, the PA system played WWE theme songs before each plate appearance by the Orioles. ... Jon Lester (14-1 lifetime vs. Baltimore) will start for Boston in the series finale. Miguel Gonzalez (2-0, 2.76 ERA vs. Boston) will start for the Orioles. ... Boston RHP Clay Buchholz hasn't sufficiently recovered from a sore neck and will not start Tuesday against Tampa Bay, manager John Farrell said. Rubby De La Rosa will start in his place if he doesn't pitch in relief before then. ... Lackey has allowed three runs or fewer in 18 of 20 starts against Baltimore.