Trailing 3-2 with 40 seconds remaining, the Capitals had pulled their goalie for a sixth attacker and the strategy paid off when Greene's shot clanged off the post and rebounded off Sabres goalie Jhonas Enroth into the net.
After a scoreless overtime, the game went to a shootout in which Washington's Matt Hendricks scored in the first round.
After Braden Holtby made a save on Tyler Ennis, Ovechkin fired a wrist shot past Enroth for the game-winner.
Ovechkin also scored in regulation while Troy Brouwer added a score for the Caps, who kept their playoff hopes alive with a fourth win in five games.
Ville Leino scored twice and Christian Erhoff also tallied for Buffalo.
Enroth finished with 35 saves.