SAN FRANCISCO — Call it the Shot That Shook the Bay.

Travis Ishikawa hit the first homer to end a National League Championship Series, a three-run shot that gave the San Francisco Giants a 6-3 victory over the St. Louis Cardinals in Game 5 on Thursday night.

These every-other-year Giants will face the Royals in an all wild-card World Series that begins Tuesday night in Kansas City, Mo.

Pablo Sandoval singled to start the ninth inning against Michael Wacha, making his first appearance of the postseason for the Cardinals. After an out, Brandon Belt walked to bring up Ishikawa, who drove a 2-0 pitch into the elevated seats in right field to set off an orange towel-waving frenzied celebration.

It was the first time a homer sent the Giants to the World Series since perhaps the most famous drive in baseball history — Bobby Thomson’s “Shot Heard ’Round the World” in a 1951 playoff.

“These guys have been through it,” Giants manager Bruce Bochy said. “They have been battle-tested and they know how to handle themselves on this type of stage, and then add to that the kids that we brought up, and then Ishikawa. I mean, what a great story.”

Ishikawa knew right away on his first career postseason homer, raising his right arm into the air as he watched his ball sail into the seats. He emphatically threw his helmet down to the dirt in triumph and joined his jubilant teammates at home plate as fireworks shot off from the center field scoreboard.

Pinch-hitter Michael Morse homered leading off the eighth against Pat Neshek, who replaced Adam Wainwright to start the inning, to tie it at 3.

Morse was batting for Madison Bumgarner, who was named NLCS MVP.

After taking a 3-1 lead in the series wild throws the past two days, the Giants used the long ball to advance to their third Series in five years by knocking out the defending NL champions. Rookie Joe Panik hit a two-run drive in the third inning off Wainwright for the Giants first homer in seven games.

Ishikawa was Pittsburgh’s Opening Day first baseman but was soon cut. He re-signed with the Giants, his original team, and went to the minor leagues before making it back to the majors.

Ishikawa took a winding journey to his winning home run, too. Earlier in the game, he misplayed a fly ball to left field that cost his team a run. He more than made up for it with his final swing.

Bumgarner did not allow a hit after Tony Cruz homered to give the Cardinals a 3-2 lead with two outs in the fourth, working eight efficient innings. Matt Adams also went deep in the fourth.

Santiago Casilla worked out of a bases-loaded jam in the top of the ninth for the win.

Adams drew a one-out walk and Daniel Descalso entered to pinch-run. Randal Grichuk singled and Descalso reached third on Kolten Wong’s grounder.

Giants shortstop Brandon Crawford snagged the chopper that glanced off diving third baseman Sandoval’s glove, then Crawford threw to second for the force.

Cruz walked to load the bases with two outs after consecutive pitches near his head, and Bochy lifted him for Jeremy Affeldt. Pitching for the fourth straight day, the lefty retired pinch-hitter Oscar Taveras on a grounder that Affeldt fielded and sprinted to first.