BALTIMORE — David Lough hit a game-ending homer in the 10th inning to cap a two-run rally against Koji Uehara, and the Baltimore Orioles beat the Boston Red Sox 5-4 on Saturday night to end a five-game losing streak.

In the top of the ninth, with Baltimore closer Zach Britton trying to secure a victory for Wei-Yin Chen, Boston loaded the bases with one out. Pablo Sandoval hit a sharp grounder to third that Manny Machado picked up before tagging the base.

His throw to first base went awry as the tying run scored.

Xander Bogaerts homered in the top of the 10th off Brad Brach before Brian Matusz (1-2) finished. In the bottom half, Adam Jones tripled off Uehara (1-1) and scored on a fly ball by Chris Davis.

Lough, who entered as a pinch runner in the eighth, followed by driving a 3-2 pitch to right.

As the ball soared toward its destination over the wall, Lough thrust his left arm into the air to celebrate the first game-ending home run of his career.

Jimmy Paredes had four hits and a homer for the Orioles, whose losing streak was their longest since September 2013.

Paredes’ long ball off Justin Masterson put Baltimore up 3-2 in the fifth.

Chen gave up two runs, four hits and a walk over eight innings.

The left-hander retired the final 12 batters he faced after Hanley Ramirez got thrown out at the plate to end the fourth.

Orioles Manager Buck Showalter missed the start of the game to attend his father-in-law’s funeral in Tennessee. Bench coach John Russell took over the team, but Showalter assumed his familiar spot in the dugout in the third inning.

Baltimore jumped ahead 2-0 when Alejandro De Aza led off with a double, Paredes followed with an RBI double and Davis delivered a sacrifice fly.

Mike Napoli got the Red Sox even in the second with a drive off the right-field foul pole after Ramirez drew a leadoff walk. It was Napoli’s first home run in 87 at-bats since Sept. 1.

Boston hit three singles in the fourth inning, but Ramirez was thrown out at the plate on the last one, a two-out liner to left by Allen Craig.

That would be Boston’s final threat against Chen, who’s got an 0.34 ERA in his last four starts against Boston dating to last season.

Notes

The Red Sox have outfielder Shane Victorino on the 15-day disabled list with a right hamstring strain.

Victorino sustained the injury while running the bases against Tampa Bay on Wednesday. He has not played since then, so the move is retroactive to Thursday.

To replace Victorino on the roster, the Red Sox recalled right-hander Matt Barnes from Triple-A Pawtucket. Barnes pitched two scoreless innings Saturday, allowing two hits.

Boston Manager John Farrell said Victorino is improving. But the manager added, “With the number of innings our bullpen is pitching, that was the overriding thing.”

Victorino is batting .143 in 12 games.

Barnes had a 5.63 ERA in two appearances with Pawtucket this season.