Marcus Johansson and Sonny Milano scored for the Capitals (8-10-3), who had lost four straight (0-3-1). Ovechkin had an assist, and T.J. Oshie had two assists in his return after missing 11 games because of a lower-body injury.
Darcy Kuemper made 21 saves for Washington, which trailed 2-1 late in the third period.
"It hasn't gone our way and we've got to start somewhere digging out," Capitals coach Peter Laviolette said. "It was a gutsy win, just staying with it. It was one of those games where it seems like you're not going to find that next one. You're pushing, you're pushing, and I thought guys just stuck to it."
Morgan Frost and Patrick Brown scored for the Flyers (7-8-5), who are 0-5-3 during their skid. Felix Sandstrom made 29 saves.
"It's definitely frustrating," Frost said. "We've got to learn how to close out a game. It's obviously huge. We thought played a pretty solid game and then we just give it away at the end. So, it's tough."
Milano tied it 2-2 at the left post with 2:58 left in the third when he converted a pass across the slot from Evgeny Kuznetsov on the rush.
"Saw 'Kuzy' had a lot of space and I just tried to match his speed," Milano said. "I got to the back door, and he threw it to that spot, and it went in."