Kelly Johnson's pinch-hit home run against Stephen Strasburg leading off the eighth inning tied things, 2-2. Later in the frame, Yoenis Cespedes hit a two-run homer off Drew Storen to give the Mets a 4-2 advantage.
After Tyler Clippard allowed a two-out solo homer to Bryce Harper in the eighth inning that cut the lead to 4-3, Michael Conforto's RBI single in the top of the ninth made it 5-3, Mets.
Jeurys Familia pitched a perfect frame in the bottom of the ninth inning to earn the save.
With the game tied, 1-1, in the fourth inning, Clint Robinson grounded an RBI single through the vacated hole at shortstop to give the Nationals a 2-1 advantage.
Bryce Harper's two-out solo home run in the first gave the Nationals a 1-0 lead, and Travis d'Arnaud hit a solo homer in the second inning to tie things, 1-1.
Jacob deGrom was largely dominant in seven innings of work, allowing two runs on five hits while walking two and striking out nine. His ERA for the season is now 2.40.
After d'Arnaud's game-tying home run in the second inning, 11 straight Mets were retired by Strasburg before Curtis Granderson drew a one-out walk in the sixth inning. Overall, Strasburg allowed three runs in 7 1/3 innings while striking out 13.
The Mets open a four-game series against the Braves on Thursday in Atlanta at 7:10 p.m. Bartolo Colon (13-11, 4.18 ERA) gets the start for the Mets. He'll be opposed by Shelby Miller (5-13, 2.81 ERA) for the Braves.