DENVER — Pete Alonso hit his major league-leading 49th homer, then drew a bases-loaded walk during a four-run rally in the ninth inning that sent the Mets over the Colorado Rockies, 7-4, on Wednesday at Coors Field.

The Mets ended the day tied with Philadelphia, three games behind the Chicago Cubs and the Milwaukee Brewers for the second wild-card spot in the National League.

Alonso hit a long solo home run to left field in the sixth, matching Mark McGwire’s total for his rookie season with Oakland in 1987. The Yankees’ Aaron Judge has the major league record for home runs by a rookie, at 52.

Jeff McNeil also went deep for the Mets, who set a franchise record with 225 home runs this season.

Trailing by 4-3 going into the ninth, the Mets tied the score on Brandon Nimmo’s third hit, a run-scoring single off Jairo Diaz. After a walk to McNeil loaded the bases, Joe Harvey relieved and walked Alonso on four pitches to put the Mets ahead.