KANSAS CITY, Mo. — On a bright afternoon in Kansas City, the Royals shaded the Texas Rangers.

Texas right fielder Shin-Soo Choo lost Lorenzo Cain's routine fly in the sun, and the ball glanced off his glove for an RBI single with two outs in the ninth inning that lifted Royals over the Rangers 4-3 Sunday.

"When I hit it, I was thinking out," Cain said. "Luckily, the sun had shifted over just enough to block his view and missing that ball. I appreciate that sun in that situation."

Choo tried to shield his eyes, but even sunglasses didn't help on Cain's sliced flyball.

"I saw the ball at the very beginning and the ball just kept going to right field and then I lost the ball," Choo said. "I'm guessing the ball's fair and just off the glove. I was trying to make the play so I can't say I was very lucky."

"You work on it during the season, in spring training on sun balls. On straight balls, on straight popups, you can have a better chance, but the ball was moving. That's a lot more difficult to catch," he said.

Cain could empathize, having to fight off the sun to make three catches in centre.

"It's a tough sun today, so I definitely knew what he was going through," Cain said.

The Royals snapped a five-game losing streak, and also ended a 12-game skid against the Rangers.

Kelvin Herrera (2-2) pitched a spotless ninth. Jason Grilli (2-5), acquired by the Rangers from Toronto on July 2, took the loss.

Alcides Escobar led off the ninth with a single for his third hit and Alex Gordon walked on four pitches. With one out, Grilli hit Whit Merrifield with a pitch to load the bases. After Jorge Bonifacio struck out, Cain delivered the game-winning hit, with some help.

Rangers right-hander Yu Darvish, who is 0-4 in his past six starts, allowed three runs in 6 2/3 innings. He gave up eight hits, walked one and struck out one.

Darvish's wild pitch in the first allowed Merrifield to score. Mike Moustakas' two-out double in the third scored Eric Hosmer, who had walked.

Royals starter Ian Kennedy yielded solo home runs to Drew Robinson in the third and Mike Napoli in the seventh.

Kennedy left after 6 2/3 innings and the score tied at 2.

Kennedy, who is winless in his past 12 home starts, gave up two runs on five hits. After throwing 25 pitches in the first inning, he navigated his way into the seventh on 74 more pitches.

"I watched some of the replays of Lorenzo battling with the sun and he happened to hit the ball into the sun to win the game, so that was ironic," Kennedy said. "It was a great way to end."

The Royals took a 3-2 lead in the seventh when Drew Butera, who had singled, scored an unearned run. Merrifield doubled and Butera came home when left fielder Nomar Mazara misplayed the ball.

Joakim Soria could not hold the lead in the eighth, charged with his seventh blown save. Mazara's two-out single scored Elvis Andrus, who had doubled.

DARVISH PASSES RYAN

Darvish moved past Hall of Famer Nolan Ryan and into fourth place on the Rangers' career strikeout list. When Darvish fanned out Brandon Moss in the fourth inning it was his 940th strikeout in his 120th start. Ryan, baseball's all-time strikeout king, fanned 939 in 129 starts with Texas.

NO GALLO

Rangers slugger Joey Gallo, who has seven strikeouts in seven at-bats against Kennedy, was not in the lineup.

GAME-ENDING GRILLI

Cain's single was the third game-ending hit Grilli has yielded in his last three outings at Kauffman Stadium — with three teams. He gave up a walk-off double to Merrifield with Toronto on June 23, and Kendrys Morales homered off him in the 13th inning to beat Atlanta on May 15. Grilli has allowed 10 walk-off hits in his career and four are against the Royals with four teams. While with the Angels, he gave up one to Omar Infante on June 29, 2014.

TRAINER'S ROOM

Rangers: RHP Keone Kela (shoulder soreness) threw a bullpen Saturday with no problems. The Rangers are unsure whether Kela needs another mound session or activate him Monday in Baltimore.

UP NEXT

Rangers: RHP Andrew Cashner will start Monday at Baltimore in the opener of a four-game series. RHP Chris Tillman will be the Orioles starter.

Royals: LHP Jason Vargas, who worked a scoreless inning in the All-Star game, will start against the Tigers. Vargas leads the AL with 12 victories and a 1.84 ERA at home.