SAN DIEGO — Second-inning homers by Kansas City teammates Eric Hosmer and Salvador Perez powered the American League to a 4-2 victory over the National League on Tuesday night in the 87th All-Star Game before 42,386 at Petco Park.

The National League was leading 1-0 thanks to a Kris Bryant homer in the first inning when Hosmer tied it with a one-out homer off National League starter Johnny Cueto. Two batters later, Perez connected for a two-run shot off Cueto.

Hosmer, who finished 2-for-3 with two RBIs, was named the Most Valuable Player.

Cleveland right-hander Corey Kluber was the winning pitcher and Baltimore left-hander Zach Britton collected the save. Cueto suffered the loss.

The National League stranded 10 runners and left the bases loaded in the eighth when Houston right-hander Will Harris threw a full-count, called third strike past pinch-hitter Aldemys Diaz of the St. Louis Cardinals.

The heavy San Diego influence of the pregame ceremonies carried into the first inning when Bryant, a University of San Diego alum, homered on the first pitch he saw from American League starter Chris Sale in an all-Chicago matchup.

The Cubs third baseman drove the ball 410 feet into the left field stands off the White Sox right-hander.

But the American League retaliated in the bottom of the second against Cueto, taking a 3-1 lead on two homers by members of the reigning World Series champion Royals.

With one out, Hosmer dropped a 389-foot drive into the left field stands to tie the score at 1. Boston outfielder Mookie Betts singled and Royals catcher Eddie Perez hit a 373-foot blast into the left field stands peppered the night before by Home Run Derby champion Giancarlo Stanton.

Hosmer and Perez were the first set of teammates to homer in the same inning since Steve Garvey and Jimmy Wynn of the Los Angeles Dodgers in the 1975 All-Star Game.

Cole Hamels continued the host city story in the top of the third when the San Diego native struck out Bryant with the tying runs at second and third with two outs.

The American League extended its lead to 4-1 in the bottom of the third against Jose Fernandez of the Miami Marlins.

Boston designated hitter David Ortiz, who has announced he will retire at the end of the 2016 season, drew a one-out walk and received an ovation from the crowd and hugs from the American League bench when he came out for pinch-runner Edwin Encarnacion of the Blue Jays.

Encarnacion raced to third on a double by Boston’s Xander Bogaerts and scored on a single by Hosmer, the second RBI by the Royals first baseman. But Betts grounded into a double play to end the threat.

The National League cut the deficit to 4-2 in the top of the fourth. Giants catcher Buster Posey drew a one-out walk from Toronto right-hander Aaron Sanchez and came around on back-to-back singles by Cubs first baseman Anthony Rizzo and Marlins center fielder Marcell Osuna.

NOTES: During pregame ceremonies, Major League Baseball announced that the batting average titles for both leagues would be named for two of the modern era’s leading hitters. The National League batting championship will be named for the late Tony Gwynn, a career-long Padres player who tied the National League record with eight batting championships. The American League batting award will be named for seven-time batting champion Rod Carew. … Randy Jones, who was the winning pitcher of the 1976 All-Star Game en route to becoming the Padres’ first Cy Young Award winner, threw out the ceremonial first pitch. … Because the 87th All-Star Game was originally scheduled for an American League city, the National League was the visiting team, although the game was played in San Diego. … The starting nine position players for the American League were all 27 years old or younger, an All-Star Game first. … There was pregame controversy when the Canadian singing group The Tenors sang the words “All Lives Count” into the Canadian national anthem.