Houston (71-44) lost its fourth consecutive game.
After being swept by the White Sox in Chicago, the Astros are in the midst of their longest losing streak of the season.
Texas (55-59) took the first game of the series by scoring five runs over the third through fifth innings, and Hamels threw his third consecutive quality start to propel the Rangers to their second win in a row and first over Houston at Globe Life Park this season.
Hamels went seven innings and allowed just three hits, improving to 7-1 with a 3.31 ERA this year. His overall record since being acquired by Texas in 2015 improved to 29-7 in 58 starts.
Houston starter Charlie Morton had his shortest outing since July 14, giving up five runs -- three earned -- on seven hits in 5 2/3 innings, snapping a streak of three straight quality starts.
The Astros made a game of it late, thanks to a four-run fourth inning. Houston was held scoreless until George Springer, in his third game back from the disabled list, hit a two-run homer off Jose Leclerc in the eighth inning.
Marwin Gonzalez and Carlos Beltran each added an RBI double to narrow the gap but Mazara's diving catch in right field ended the threat. With two runners on in the ninth inning, Rangers reliever Alex Claudio struck Jose Altuve out looking to end the game.
NOTES: Houston RHP Will Harris threw off flat ground as he works back from a bone bruise and right shoulder inflammation. ... Houston RHPs Lance McCullers and Michael Feliz, as well as LHP Tony Sipp and C Evan Gattis, did not travel to Arlington and remained in Houston to work out. ... Before the game, the Rangers activated RHP Jhan Marinez, whom they claimed off waivers from Pittsburgh, and sent INF Tyler Smith to Triple-A Round Rock to make room on the roster. ... Houston OF George Springer hit his first home run since July 7. With his home run and IF Marwin Gonzalez's RBI double, Springer and Gonzalez each lead the Astros with 68 RBIs this year. ... Rangers 3B Adrian Beltre collected his 606th career double, passing Paul Molitor for 14th all-time.