Curtis Granderson scores on a sacrifice fly by T.J. Rivera during the fifth inning of the Nationals’ 4-3 loss to the Mets. (Alex Brandon/Associated Press)

As the number of games remaining dwindles like September’s evening light, the Washington Nationals seem as unwilling to let go as the summer heat, holding themselves comfortably atop the National League East for a month or so now.

After their extra-inning loss to the New York Mets on Tuesday night at Nationals Park, just their second loss in nine games, the Nationals seemed upbeat and mostly unfazed, buoyed by a ninth-inning comeback against one of the best closers in baseball, unconcerned about the home run hit against their closer in the 10th.

Perhaps, with a nine-game lead and 17 games to play, consolation prizes do exist. Perhaps those circumstances permit moral victories, like the one the Nationals won in the ninth on Tuesday.

The Nationals could, and perhaps should, have won Tuesday’s game instead of falling by the score of 4-3. But they have once again shown they can erase late-game deficits against elite relievers — and that they are never quite out of it, whatever such knowledge is worth.

“I’m very proud of them,” Nationals Manager Dusty Baker said. “We came back. The mark of a champion is when you figure out a way to win and come back. Even though we lost that game, that game is going to go a long ways with us and our quest for the championship. Those guys over there are fighting for their lives, too.”

Discard the rose-colored glasses, which blurred a game that got away, and find that “those guys over there” won Tuesday night’s battle. They did so because of a solo home run from rookie T.J. Rivera in the 10th, one that came off an 0-2 cutter from Nationals closer Mark Melancon.

Melancon appeared 45 times in four months with the Pirates but has now appeared 22 times in six weeks with the Nationals — including four out of the last five days. He admits he feels the effects of that increased workload, which is in part attributable to Baker’s willingness to turn to Melancon in non-save situations, but said he enjoys working through those challenges and adjusting to deal with them. He had allowed two home runs in 0-2 counts in his entire career before Rivera’s.

“Tip your cap. Good swing on it,” Melancon said. “You always learn from your mistakes. That’s not going to affect me going forward. Sometimes those wakeup calls can be a good thing.”

But to extend the game for Melancon at all required the Nationals to do something teams had accomplished three times in 51 tries against Mets closer Jeurys Familia all year — come back in a save situation.

Noah Syndergaard had shut the Nationals down through seven innings, striking out 10 and walking one. In his second start against the Mets in two weeks, A.J. Cole allowed nine hits and three runs in five innings. He left trailing 3-1, which was the score when Familia entered to face Daniel Murphy, Bryce Harper and Anthony Rendon in the ninth.

Murphy had already doubled, giving him a hit in all 18 games the Nationals have played against the Mets this season, the longest hitting streak anyone has ever had against them. In the ninth, he chopped a groundball up the middle. Rivera made a sliding stop but could not throw to first in time to get Murphy.

Then Harper hit a dribbler to third baseman Jose Reyes with an exit velocity comparable to the speed of Beltway traffic at rush hour, if that. Reyes charged, rushed his throw and threw it away, which put the tying runs in scoring position with no one out.

Anthony Rendon drove Murphy home with a groundball through the left side. Wilson Ramos hit a chopper over Familia, who could not secure it, to tie the game.

“Just about grinding out at-bats,” Murphy said. “Jeurys is tough. I saw him all year last year from behind him. He’s tough in there, and to be able to grind out at-bats like that and turn 3-1 into 3-3 was a good inning for us.”

Ramos’s hit left the Nationals in a good position to win it, with runners on first and second and no one out. Baker pinch-ran for Ramos, whose run did not matter, with Wilmer Difo — trying to stay out of a double play or draw a throw, Baker explained later.

Ryan Zimmerman hit a blooper to second. Then Clint Robinson hit a low line drive to Rivera, which Difo said later he assumed was going to short-hop the second baseman. It didn’t, and Difo was doubled off first, ending the rally — but not the game. After Rivera homered in the 10th, Murphy struck out against former National Jerry Blevins to end the game. Melancon took his first loss as a National.

“[Difo] was just trying a little bit too hard. He’ll learn from it,” Baker said. “His run didn’t mean anything, so that’s what happens sometimes. Especially when you’re excited and you’re a kid. Sometimes young players will make mistakes, and hopefully they’ll learn from it.”

The Nationals can afford a learning experience or two these days, in a position to give young guys a chance while absorbing their mistakes. Perhaps rose-colored glasses are a more acceptable wardrobe choice when a team is talking about its magic number than when it is trying to keep another team’s where it is.

“It’s a big game tomorrow. It’s a rubber-match game. Win tomorrow and we’re back to 10 up,” said Baker, who would rather not enjoy another moral victory Wednesday all the same.