Hamels (4-1) pitched 24 consecutive scoreless innings before Jonathan Schoop belted a solo homer in the fourth. Adam Jones and Mark Trumbo also homered off Hamels, who had allowed only five long balls in his previous nine starts.
Joey Rickard had an RBI single with one out in the sixth that tied the game 5-5 and ended Hamels' night. Hamels, who was out from May to late June with a right oblique strain, tied a season high by allowing seven runs. He also yielded nine hits.
Jeremy Jeffress entered and allowed a go-ahead RBI double to Jones. Two batters later, Schoop provided an 8-5 lead with a two-run single up the middle.
Orioles left hander Wade Miley struggled again, allowing five runs, seven hits and four walks over five innings.
Welington Castllo and Ruben Tejada had three hits apiece for Baltimore, which managed its first four-game home sweep of Texas since 2014.
Miguel Castro (2-1) picked up the win with a perfect sixth.
After struggling to generate much offense over the first three games, Texas finally came up with a several clutch hits off Miley.
The Rangers took a 1-0 lead in the first on a two-out single by Beltre, who was thrown out by right fielder Rickard trying to take second.
Texas extended the lead in the fourth with two outs again on an RBI double by Carlos Gomez down the right field line.
Schoop pulled the Orioles to within 2-1 with his solo shot in the bottom half. Hamels then hit Trey Mancini with a pitch and issued a pair of walks that loaded the bases. He ended the threat by getting Tejada to ground out.
The Rangers responded in the fifth on Napoli's three-run homer -- his 21st of the year -- that also came with two outs.
Baltimore came back that inning with a two-run homer by Jones and solo shot by Trumbo that cut the margin to 5-4.
NOTES: The Orioles did not take batting practice with the heat index hovering above 100 degrees. The Rangers did hit before the game. ... Orioles RHP Mike Wright (right shoulder bursitis) is scheduled to throw two innings Saturday in the rookie-level Gulf Coast League. ... Texas RHP Keone Kela (right shoulder tightness) was activated from the disabled list Thursday. To make room, INF Pete Kozma was designated for assignment.