Ian Desmond led off the inning with a walk and was on base when Harper connected for his fourth homer of the season.
The game-winning blast came just one day after manager Matt Williams told reporters there was no way Harper would be sent to the minors because of a recent slump. Harper had five hits in his last 28 at-bats before the homer.
The winning pitcher was Craig Stammen (2-4) and Torres (5-5) took the loss.
The Nationals lost their first five extra-inning games at home this year and are now 4-8 overall in such games. The Mets are 6-8.