BALTIMORE (AP) Ryan Rua has struggled over his young career as a pinch hitter for the Texas Rangers.

However, he made the most of the opportunity against the free-falling Baltimore Orioles.

Rua had a tiebreaking, pinch-hit three-run homer in the seventh inning and the Rangers held on to beat the Orioles 5-4 Friday night to snap a three-game losing streak.

''It was a situation where we just felt if we had runners on base we were going to go to Rua to give us an opportunity to drive some runs in,'' Rangers manager Jeff Banister said. ''I'm not real sure if he's had a pinch hit. I know he's had some attempts and hadn't really come through. But to get a big one in that situation was huge for us.''

Cole Hamels (5-8) won for the first time in almost a month, allowing four runs and five hits with three strikeouts and one walk over 6 1/3 innings in a matchup of last-place teams.

''I was still giving up four runs, so that's tough,'' Hamels said.

Rua broke a 1-1 deadlock with the first pinch-hit of his career, off rookie left-hander Tanner Scott. Rua had gone 0 for 18 in his previous opportunities in that role.

''In my career I've had pretty good success against lefties,'' Rua said. ''Pinch-hitting, not so much, so it was good to get that out of the way.''

Nomar Mazara added an RBI double later that inning, which made it 5-1 and boosted Scott's ERA from 5.88 to 6.84 over 26 appearances.

Baltimore pulled within a run on Caleb Joseph's three-run double against reliever Jose Leclerc in the bottom half of the inning. The Orioles loaded the bases in the eighth but Jake Diekman got out of the jam by getting Chris Davis on a short pop out.

Keone Kela got the last three outs for his 23rd save.

''I don't know how many one-run games we've had where we've fought back, fought back and just haven't been able to get that big push,'' Joseph said. ''It'll take a toll on you mentally, for sure.''

The Orioles have lost 17 of 20 and fell to 14-33 at Camden Yards, the second-worst home mark in the majors behind Kansas City.

Joey Gallo gave the Rangers the lead when he led off the fifth with a home run off Alex Cobb (2-12). The Orioles answered in the bottom half when Adam Jones hit a double just inside the left-field foul line and later scored on a sacrifice fly by Danny Valencia.

Cobb left his previous start against the Twins in the sixth inning with a blister on his right index finger. He did not appear hampered by the injury and allowed two runs and six hits with three strikeouts and no walks over 6 1/3 innings.

''They're a pretty aggressive team,'' Cobb said. ''I tried to get ahead early, make them chase pitches that you want them to chase, and hopefully, they put it on the ground and find somebody.''

STREAKS EXTENDED

Rangers DH Shin-Soo Choo, who was celebrating his 36th birthday, hit a single in the third to extend his club record on-base streak to 49 games. It's also the longest streak in the majors in the last 10 years. ... Hamels has struck out at least one batter in 320 straight games.

STATS AND FACTS

The Orioles used their 90th different lineup, the most in the MLB. ... Baltimore 1B Davis stole a base for the first time since last Sept. 24.

TRAINER'S ROOM

Orioles: RHP Chris Tillman (back) will have another rehab start for Triple-A Norfolk on Sunday. He could be added to Baltimore's roster after the All-Star break, manager Buck Showalter said.

UP NEXT

Rangers: LHP Martin Perez (2-3. 9.67 ERA) will come off the 60-day DL from an elbow injury and make his first start since April 29. He went 2-0 with a 0.52 ERA and 19 strikeouts in three rehab outings (17.1 nnings).

Orioles: Rookie Yefry Ramirez (0-3, 3.93 ERA) will make his fourth start of the season. He allowed four runs and nine hits over four-plus innings in a loss to the Yankees on July 9.

------

More AP baseball: https://apnews.com/tag/MLBbaseball

Copyright 2018 by AP. Any commercial use or distribution without the express written consent of AP is strictly prohibited.