Alex Ovechkin’s goal 22 seconds into overtime lifted the Capitals past the Maple Leafs. (Toni L. Sandys/The Washington Post)

The game was a goal-scoring display, so it was only appropriate for Alex Ovechkin to be the one who would win it. He slammed in a pass from John Carlson on the first shift of three-on-three overtime then kicked up his knee in celebration.

The Capitals overcame a two-goal deficit in the third period and went on to beat the Toronto Maple Leafs, 6-5, after 22 seconds of overtime at Verizon Center. Washington’s strength has been its defense, but on Tuesday night, its offense was up to the challenge of a high-scoring affair.

“Different games have different story lines, and sometimes you’ve got to score six and sometimes you just need one,” said Capitals forward Justin Williams, who had a three-point night.

“It was a great game,” Ovechkin said. “Fun game.”

With the game tied at 4 past the midpoint of the third period, Maple Leafs rookie Mitch Marner got behind everyone. His youthful legs propelled him toward Capitals goaltender Philipp Grubauer — who had long since replaced an ineffective Braden Holtby — too fast for anyone to catch him. He unfurled a wrist shot, and Grubauer seemed to think he had secured the puck between his legs. But then it trickled out and into the net, and the goaltender leaned forward in frustration.

The game may not have been fun for the goaltenders, but everyone else seemed to enjoy it because no lead was safe. Less than three minutes after Marner’s goal, Evgeny Kuznetsov got a breakaway. Toronto goaltender Frederik Andersen saved his shot, but Carlson swatted in the rebound to again tie the game with 6:05 left in regulation. That set up a fittingly wild finish.

“More so than scoring goals, it’s just the fact that we were able to come back from the deficit,” Capitals forward T.J. Oshie said. “It seemed like every time we’d get a goal, they’d come right back and get one or two.”

Toronto had seemingly taken control in the second period, when Maple Leafs star rookie Auston Matthews skated behind the net then spun completely around and dished the puck to Leo Komarov in front. Komarov wristed it in to give Toronto a 4-2 lead before turning to Capitals defenseman Brooks Orpik, giving him a mocking conciliatory pat on the shoulder. Orpik gave Komarov a shove in frustration, and the scene illustrated how the game was going for Washington.

Three Toronto goals on eight shots in the first period chased Holtby, and he was replaced by Grubauer to start the second period. The Capitals took seven minor penalties, and three were in the offensive zone. Nazem Kadri scored on the power play in the first period, tying the game 1-1, and Komarov’s goal also came on the power play, after Ovechkin was called for tripping. Entering the game, Washington’s stingy shorthanded unit had killed 40 of the team’s previous 41 penalties.

But within the first four minutes of the third period, the Capitals tied the game. Kuznetsov, a pass-first player who didn’t score a goal in the month of December, wristed a puck past Andersen from the slot. Just 1:19 later, defenseman Dmitry Orlov tied the game with a one-timer set up by Matt Niskanen. Kuznetsov finished with a four-point night.

“Kuzy was skating,” Capitals Coach Barry Trotz said. “That looked like the Kuzy that we all know and love, when he’s skating. . . . He was dangerous.”

Entering the game, Washington was tied for first in the league allowing 2.06 goals per game, but its offense had slumped at times this season. Fortunately for the Capitals, their offense was up to the challenge Tuesday night.

“It was fun,” Williams said. “It felt like we needed a little excitement in here. Certainly, I think we just kind of willed our way to that win. It was fun and exciting for everybody.”