When spring training ended, Pete Alonso barely made the team.

On Tuesday, he made history.

Alonso set a new Mets’ franchise record with his 42nd home run, breaking the mark shared by Carlos Beltran and Todd Hundley.

It came in a 5-2 loss to the Cubs at Citi Field, but the 407-foot opposite field blast off Yu Darvish’s first pitch of the bottom of the fourth gave the Mets a 1-0 lead.

“As soon as ball came off bat, I knew right away,’’ Alonso said. “I made such good contact. It was such an amazing feeling. It’s been a dream come true so far this year.”

Alonso became the first rookie to set a team’s franchise home run record since Johnny Rizzo did it for the Pirates in 1938, according to Elias Sports Bureau. The only rookies to ever hit more homers in a season are Aaron Judge, who hit 52 with the Yankees in 2017 and Mark McGwire, who had 49 for Oakland in 1987.

The music from “The Natural” played as Alonso rounded the bases and after he crossed home plate, Alonso saluted the fans and came out for a curtain call with Michael Conforto at the plate.

“The appreciation I have for these Mets’ fans, the support I’ve gotten has been surreal,’’ Alonso said. “The way they’ve embraced me since Day 1 has been extremely special. … I just wanted to reciprocate that.”

“He’s a special player,’’ Mickey Callaway said. “There’s not a ton of guys like him.”

Hundley set the record in 1996 and Beltran followed a decade later. Both released statements Tuesday night, as Alonso blew by them with 31 games remaining this year — in a season that has already seen plenty of home run records fall.

“It’s a pleasure to have a fine young player like Pete Alonso break my record,’’ Beltran said. “I have not met Pete personally, but people have told me he plays the game with passion and doesn’t give up on any at-bat. He has had great success in his first year. Again, my congrats, Pete.”

Hundley called Alonso “more than a power hitter, he’s a pure hitter. I have seen five or six of his games and he keeps getting better and better. He has just had a tremendous year. Congrats, Pete you deserve all the records you have broken.”

Alonso reflected on the path that began with him being put on the roster out of spring training, when there had been thought he could start the year at Triple-A in an effort to save a year of service time for the Mets.

“When I found out I made the team, I wanted to make the biggest impact possible,’’ Alonso said. “I wanted to stay up here. I didn’t want to do the whole up-and-down situation. I wanted to be a focal point.’’

He’s more than succeeded in that respect.

But now that they’ve lost four straight, Alonso’s heroics might not be enough.

“We still have a really good opportunity this year,’’ Alonso said. “There’s a lot of ballgames left. Plenty of people wrote us off and continue to write us off. We’re just gonna keep on working and do the best we can to make the playoffs. … The job’s not done yet.”

Purchase event tickets to The Amazin’ 1969 New York Mets: A World Championship for the Ages presented by The Paley Center for Media and New York Post. Enter promo code: NYPOST to unlock tickets only available for Post readers.