Hamels, who is 6-1 with a 2.24 ERA in his past nine starts, limited the Royals to five hits, struck out four and walked three. Hamels (11-2) lowered his ERA to 2.87, which is tied for third in the American League.
"A gritty performance," Rangers manager Jeff Banister said. "Obviously, we made it challenging for him with some of the misplays, but he was able to cover them up."
The Rangers picked up only their fifth victory in 20 games. Hamels has started three of those victories.
"It's not too cool here right now," Hamels said of the weather, which had a heat index of 104 degrees for the first pitch. "You just try to stay cool. The other guy has got to do it, too. It's just a matter of trying to outlast your opponent. They're a good team. I'm aware of that. I tried to make pitches when you have to."
Mazara homered in the fourth with Jurickson Profar, who had walked, aboard, which was the first hit off Royals starter Yordano Ventura. Mazara, who tops all American League rookies with 25 games with multiple hits and 141 total bases, doubled to center in the fifth, scoring Delino DeShields.
Beltre, a career .363 hitter at Kauffman Stadium, hit a three-run homer in the Rangers' four-run seventh off Joakim Soria. Ian Desmond singled in the first run of the inning. Soria has allowed six runs in his past two outings and has a 9.72 ERA in his past nine relief appearances.
Ventura was struck in the right rib cage by a Beltre laser to end the fifth. After Ventura threw to first base, he collapsed to the ground in pain and was attended to by trainer Nick Kenney. X-rays were negative, but Ventura did not come out for the sixth. Ventura (6-8) gave up three runs on three hits and four walks while striking out five.
"I got hit in the rib, obviously, and just lost my breath," Ventura said through an interpreter. "I was trying to just regain my breath. It hurt at first but I recuperated pretty good."
He said he does not anticipate missing a start.
Cheslor Cuthbert doubled with one out in the first, extending his hitting streak to a career-best 12 games and took third on Mazara's fielding error. Cuthbert scored on Eric Hosmer's groundout for the only run off Hamels.
The Royals scored three runs in the ninth on four singles and a bases-loaded walk before Salvador Perez grounded into a double play to end the game.
"It's a big deficit heading into the last inning," said Hosmer, who drove in a run in the ninth with an infield single. "We did a good job of getting to Hamels a little bit, getting him in some situations and getting him out of there early, but it kind of got away from us before we can fire back at their bullpen."
RANGERS ADD DUFFY
The Rangers claimed 1B Matt Duffy off waivers from the Astros and assigned him to their Triple-A Round Rock club. Duffy, 27, hit .294 with 20 home runs, 29 doubles and 104 RBI last season with Fresno in the Pacific Coast League. He was hitless in three at-bats this season with Houston.
Rangers: LHP Derek Holland, who is on the 60-day disabled list with shoulder inflammation, threw his first bullpen session, 25 pitches, since going on the DL. If he has no setbacks, Holland could begin a minor league rehab assignment in early August.
Royals: LHP Mike Minor, who had labrum surgery in 2015, threw a simulated game but has yet to pitch in a big league game this season.
Rangers: RHP A.J. Griffin will be working on five days' rest Sunday after a no-decision Monday at the Angels.
Royals: RHP Edinson Volquez is 0-2 with an 8.22 ERA in three career starts against the Rangers, his first club.
Atlanta looks to clinch pennant with victory over Los Angeles
Atlanta Braves (88-73, first in the NL East) vs. Los Angeles Dodgers (106-56, second in the NL West)
Eddie Rosario's 4-hit, 2-homer night gives Atlanta Braves 3-1 lead over Los Angeles Dodgers in NLCS
Eddie Rosario banged out four hits -- including two home runs -- to lead Atlanta over the Dodgers on Wednesday night and to a 3-1 lead in the NLCS.
Los Angeles Dodgers All-Star Justin Turner likely out for rest of postseason with hamstring injury
Dodgers manager Dave Roberts said the early indication is that Justin Turner has a Grade 2 hamstring strain. "So, I think that'll be it for him," Roberts said.
MLB playoffs 2021: Best plays and moments from Houston Astros-Boston Red Sox, Atlanta Braves-Los Angeles Dodgers
Wednesday had another double-header of league championship series action, with the Houston Astros and Atlanta Braves coming away with crucial victories.
Braves blast 4 HRs, beat Dodgers 9-2 for 3-1 lead in NLCS
— Behind the red-hot bat of Eddie Rosario, the Atlanta Braves are one win away from their first World Series appearance since 1999.
Rosario cranks 2 HRs as Braves put Dodgers on brink of elimination
Eddie Rosario hits a pair of home runs in the Braves' 9-2 Game 4 win vs. the Dodgers.