Pete Alonso hit a game-ending homer with one out in the seventh inning and the New York Mets quickly bounced back from blowing the lead, beating the Washington Nationals 5-4 Thursday for a doubleheader sweep.

The Mets won the opener 4-1 as Brandon Nimmo homered and drove in four run and Marcus Stroman took a shutout into the sixth.

CLICK HERE FOR MORE SPORTS COVERAGE ON FOXNEWS.COM

New York took a 4-1 lead, too, into the seventh of the second game before the Nationals rallied against Trevor May and Jeurys Familia (6-2). A run-scoring wild pitch by Familia and Andrew Stevenson’s two-out, two-run single tied it.

Alonso capped a long, humid day with his 25th homer, lifting a 2-0 sinker against Kyle Finnegan (4-4) for a high-arcing drive to left field beyond the leaping try of Stevenson.

Alonso flung his helmet in the air and was mobbed by his teammates at the plate. Before heading into the clubhouse, the All-Star Home Run Derby champ ripped off his jersey to the cheering fans.

It was Alonso’s second career game-ending homer and fourth career game-ending hit.

Heading into a stretch of 13 straight games against talented NL West teams San Francisco and Los Angeles, the Mets won their third straight, their best string since taking three in a row from June 14-16.

The three-game sweep of the Nats followed a recent rut of seven losses in eight games that dropped the Mets out of the NL East lead.

Washington, which traded away eight players at the deadline, lost for the 16th time in 21 games

Starter Trevor Williams allowed one run and three hits in 4 1/3 innings and became the 18th starter used by New York. The team record is 20 set in 1967, Hall of Famer Tom Seaver’s rookie season.

Jonathan Villar hit his 13th homer, connecting off Tanner Rainey for a two-run drive that put New York ahead 4-1 lead.

Nimmo tied a career high with four RBIs. He hit a three-run homer in the second against Sean Nolin (0-1) and singled in the fourth to make it 4-0.

Stroman (8-11) allowed one run and three hits in 5 1/3 innings to break a three-start losing streak. He struck out eight and walked two.

Stroman had a bunt single in the third that eluded Nolin on the third base side of the mound as Nationals third baseman Carter Kieboom played back. Nimmo followed by hitting Nolin’s full-count cutter over the right-field fence.

Edwin Díaz tossed a scoreless seventh for his 25th save in 29 chances.

Victor Robles hit an RBI double for Washington.

CLICK HERE TO GET THE FOX NEWS APP

OUCH

Reliever Andres Machado replaced Nolin and hit his first batter, Alonso, on the hand with a 95 mph fastball.

Alonso fell down and said something to Machado, and a few Mets jumped over the dugout railing. Umpires spoke to Machado briefly and things did not escalate further.

COUNT TO 12

Thursday was the Mets' 12th doubleheader and they have two more remaining on Aug. 31 against Miami and Sept. 4 in Washington. New York has swept three doubleheaders and split the other nine.

LONG TIME

In the opener, Washington’s Seth Nolin allowed four runs on eight hits in three-plus innings in his first major league appearance since Oct. 3, 2015, with the Oakland Athletics.

"I definitely wasn’t as nervous this time," Nolin said. "I feel like I had a lot of positive, good energy. Just the last couple of days and early morning probably helped as well, but I wasn’t too overenergetic."

TRAINER’S ROOM

Mets: SS Javier Báez (lower back) was held out of the lineup.

UP NEXT

Nationals: Washington did not announce a starter for Friday’s series opener against Atlanta.

Mets: Rookie RHP Tyler Megill (1-2, 3.20 ERA) opposes Los Angeles LHP Julio Urías (13-3, 3.41) in the opener of a three-game series on Friday.