The Nationals maintained a one-game lead over Milwaukee in the race for the top NL wild card.
Washington trailed 2-1 when Asdrubal Cabrera singled and Yan Gomes doubled with one out in the seventh. Victor Robles followed with a sacrifice fly that tied the game. Difo, making his first start since May 16, followed with a single to right-center off reliever Mike Morin (1-3) that scored Gomes.
"He gets a chance to play and plays good defense, gets a couple hits -- big hit -- but he played really well," manager Dave Martinez said of Difo. "We talk about that all year long, about utilizing every guy you have on the roster and that's a perfect example of him just being ready to play when he's called upon."
"We had fun last night," Dozier said. "It was good. Obviously, we're still fighting. All these (games) definitely matter."
Sanchez (11-8) allowed two runs and six hits, striking out seven without a walk. Sean Doolittle earned his first save since a stint on the injured list. He pitched a scoreless ninth for his 29th save in 35 attempts and first since Aug. 16.
Phillies starter Drew Smyly allowed two runs in 6 1/3 and struck out a season-high 10 batters.
Harper expressed his displeasure with Nationals fans who taunted him in right field. He said the language coming from the stands over the first seven innings was what he usually hears on the road, but it got worse over the final two innings, though Harper declined to reveal what was said.
"I guess that's what it is nowadays," Harper said when asked if he was surprised by the vitriol. "Like I said the whole time, I've got 60,000 fans up in Philly that appreciate me as a player, appreciate me as an individual and my family as well. I owe a lot to those people up there in Philly because they show up for me every single night and they're there to cheer us on and boo us and keep us going as a team and as individuals as well. I'm looking forward to the next 12 years. Can't wait."
"I still want to play these games to win," Nationals manager Davey Martinez said. "But we got to be smart about giving guys some days off. Today is no Anthony, no Trea. Both deserve days off, obviously. We'll see how it goes, and hopefully get Juan a couple of days off in the near future."
With the Phillies eliminated from playoff contention Tuesday, Gabe Kapler was asked about his future with the club. He is 159-161 with the Phillies, who spent heavily in free agency in the offseason but will miss the postseason for the eighth consecutive year.
"There's going to be time to reflect on my future when we get to the end of the season," Kapler said. "Right now, my job is to continue to stay focused on managing the major league club and devoting myself to the organization, and I'm going to continue to do that through the end."
Phillies: C J.T. Realmuto will miss the remainder of the season with a right knee injury. Kapler said Realmuto has returned to Philadelphia and will undergo a "meniscus cleanup" on Friday. "There's no long-term concerns about this for J.T.," Kapler said.
Nationals: C Kurt Suzuki (elbow) was working on throws to the bases before the game. He hasn't started a game since Sept. 5. "He threw about 90 percent, feels good," Martinez said. "So we will do it again tomorrow, see how he feels. I'm shooting for maybe Friday and Saturday to get him in the game."
Phillies: LHP Jason Vargas (7-8, 4.40 ERA) makes his final start of the season as the five-game series concludes.
Nationals: RHP Stephen Strasburg (17-6, 3.37) is 13-2 with a 2.62 ERA in 26 career starts versus the Phillies.
More AP MLB: https://apnews.com/MLB and https://twitter.com/AP-Sports
Derek Jeter's greatest moments
Take a look back at Yankees icon Derek Jeter's most memorable moments.
2020 Baseball Hall of Fame: Whom did our voters pick?
Derek Jeter looks like a lock to reach Cooperstown in his first year, but could Larry Walker be Hall bound in his last year on the ballot?
Predicting MLB's Hall of Fame selections through the 2020s
With the Class of 2020 set to be announced, we look at who will -- and won't -- be heading to Cooperstown in the decade ahead.
Using technology to steal signs in MLB
Eduardo Perez gives an in-depth breakdown of how technology is used to steal signs and then relay information to the batter during a game.
Teixeira: Integrity of game lost if electronic devices were used
Mark Teixeira calls for massive punishments if it is proved that players used electronic devices to get tipped of pitches.
Rob Manfred's mistake was giving sign stealers too much leeway
The commissioner could have nipped the embarrassing scandal in the bud with a strong statement early on.