Ovechkin's goal was a highlight-reel effort. He pushed the puck through Henrik Tallinder's legs just inside the blue line and fired a shot past goalie Patrick Lalime while falling, giving the Capitals a 3-1 lead.
Washington improved to an Eastern Conference-best 14-1-1 at home. The Capitals are 8-10-2 on the road.
Thomas Vanek had his 25th goal for Buffalo, and Maxim Afinogenov also scored.
Washington opened the scoring on Kozlov's hard shot from near the right boards with 2:14 left in the second period.
Ovechkin appeared to score 1:09 later, but a goalie interference call against teammate Brooks Laich negated that.
The Capitals rebounded from that 1:58 into the third period when Gordon redirected Milan Jurcina's shot past Lalime.
Buffalo made it 2-1 on Vanek's power-play goal at 6:13 of the third period.
Ovechkin gave the Capitals a two-goal edge with his big play, and Buffalo's Maxim Afinogenov completed the scoring with 1:49 left.
Notes: Washington RW Chris Clark returned after missing 14 games because of a forearm injury. ... Capitals D Bryan Helmer had two assists. ... Afinogenov's goal hit his feet and deflected into the net while he was jumping to get out of the way of Toni Lydman's shot.