The Nationals forced extra frames when Ian Desmond socked a score-tying homer in the bottom of ninth and then went on to win in bizarre fashion in the next inning.
Lidge (0-1) allowed a lead-off double by Ryan Zimmerman and Jayson Werth singled after Lidge had intentionally walked Michael Morse. The veteran Phillies reliever struck out Danny Espinosa before hitting Gomes on the left arm to force in the game-winning run.
Espinoza went 3-for-5 with a solo homer and two RBI for Washington.
Sean Burnett (4-5) earned the win for the Nats, who took the rubber match against the National League East leaders.
Carlos Ruiz hit a two-run homer and Chase Utley added a solo shot for the Phillies, who blew ninth-inning leads in two of their three losses to Washington.