SCOTTSDALE, Ariz. -- Pablo Sandoval crushed a two-run homer in the ninth off Royals reliever Greg Holland to give the Giants a 4-2 walk-off win on Monday.

It was Sandoval's third hit, as the slugger finished a triple short of the cycle.

Strong pitching dominated the day before Sandoval's homer.

Kansas City starter Luis Mendoza threw five shutout innings while yielding only three hits and two walks. Mendoza lowered his ERA to 0.54. The rookie right-hander is competing for one of the remaining two spots in the Royals' rotation, and he continues to be unflappable through the spring.

"It's felt great all spring long," Mendoza said. "I've just been trying to make my pitches with a purpose and just trust them."

The Giants countered with Ryan Vogelsong, who made his Cactus League debut and pitched well for 2 2/3 innings, coming out on a strict pitch count after hitting 39. He gave up a leadoff double to Alex Gordon, then fielded a sacrifice bunt from Chris Getz and saw Gordon score on a grounder to short. He gave up one more hit, a third-inning double from Alcides Escobar, and struck out two, using all his pitches.

"I definitely felt better the second and third inning mechanically and rhythm-wise," said Vogelsong, making his way back from a back strain. "I kind of fell into a good rhythm after the first inning, get that first one out of the way and get back to business."

The Giants also sent bullpen stalwarts Jeremy Affeldt, Brian Wilson, Javier Lopez and Sergio Romo to the mound, with all but Romo putting up goose eggs. Jeff Francoeur touched Romo for a leadoff double to right in the seventh, and after Romo got the next two outs, Humberto Quintero stepped to the plate for a pinch-hit RBI single.

San Francisco battled back in the bottom of the inning, getting the first two batters on base via a walk and a single to left from Mike Fontenot. Royals first baseman Billy Butler got the front end of a potential double play by stepping on first, but shortstop Escobar couldn't handle the throw, putting the Giants on the scoreboard.

The Giants tied the score in the eighth as Sandoval stroked his second hit of the game, a double to left, to lead off the inning. He was plated by Joaquin Arias, who entered the game in the third inning when starting shortstop Ryan Theriot took a ball to the face and left the game with a bloody nose.

Up next for Royals: Left-hander Bruce Chen has an unsightly 15.00 ERA and was hammered for 10 runs by the White Sox in his last start. However, manager Ned Yost says, "Bruce has got a plan, he knows what he's doing, he'll be ready." Chen gets his next chance at 3:05 p.m. CT on Tuesday against the Brewers at Maryvale Baseball Park. Tim Collins, Louis Coleman and Sean O'Sullivan also are scheduled to pitch.

Up next for Giants: Opening Day starter Tim Lincecum (2-0, 4.50) makes his second-to-last start of the Cactus League on Tuesday, when the Giants host the Angels at 1:05 p.m. PT, in a game that can be seen on MLB.TV. Lincecum pitched a Minor League game in his last start, rather than face the National League West rival Rockies a couple weeks before seeing them in the season's second series, so this penultimate spring start against the Angels should be a good test for him. It will also be Lincecum's first game of the spring working with Buster Posey, who will catch back-to-back games for the first time this year.