The Capitals’ Tom Wilson looks to redirect the puck as Colorado’s Semyon Varlamov makes a save during Friday night’s game. (Doug Pensinger/Associated Press)

The cacophony of pings haunted the Washington Capitals, one shot after another clanging off the post or crossbar. Four shots found metal in the first 28 minutes and 50 seconds at the Pepsi Center on Friday night, but then puck luck finally turned for the Capitals.

A three-goal second period pushed Washington ahead of the Colorado Avalanche for good in a 4-2 win, a franchise-record 55th victory . It was goaltender Braden Holtby’s 47th win, moving him within one of matching Martin Brodeur’s single-season wins record of 48.

Over the past week, Washington has seen its defense round into form. On Friday, the offense finally came back, too. The Capitals finished with a 47-19 advantage in shots on goal.

“The only reason the game was close was [goaltender Semyon] Varlamov and the posts,” Capitals Coach Barry Trotz said. “We could’ve lit them up tonight.”

A goal by Gabriel Landeskog with less than six minutes remaining narrowed what was a 3-0 Washington lead to just one goal. But the Avalanche couldn’t complete the comeback and T.J. Oshie added an empty-net goal with less than 10 seconds remaining. Against a desperate Colorado team fighting to get back into playoff position, the Capitals played one of their most complete games in the last two months.

“It was something that we definitely were focusing on,” Jay Beagle said. “We were talking about for the last two or three weeks, putting a full 60 together. We did that tonight.”

Though Trotz had praised his team for limiting the chances against in recent games, the Capitals had their own scoring troubles. Entering Friday’s game, the team had just two five-on-five goals in its past four games. In back-to-back games last weekend, the Capitals were shut out in consecutive regulations for the first time in four years. They got two even-strength goals against the Blue Jackets, but their lone goal against the Philadelphia Flyers came as the power play was expiring.

Washington had hit two posts against the Flyers, and Nicklas Backstrom’s shot that clanged in overtime would’ve won the game had it been on target. Backstrom didn’t play against the Avalanche on Friday, out for precautionary reasons with an upper-body injury. That created a top line of Alex Ovechkin and Oshie centered by Marcus Johansson.

That line nearly scored in the opening minute, but Johansson’s snap shot ricocheted off the crossbar. Barely six minutes into the game, Mike Richards hit a post. About 10 minutes later, Beagle had a shorthanded breakaway, and his shot hit the crossbar. The Capitals had one of their stronger first periods of the season, putting 15 shots on net, but had nothing to show for it.

“Luck wasn’t on our side tonight,” Holtby said. “And we still battled through.”

An Oshie shot dinged a post 3:31 into the second period, the Capitals’ fourth time being denied by iron. But Beagle got his revenge nearly nine minutes into the second period. He forced a giveaway with good forecheck pressure behind the net, then backhanded the puck in the narrow opening between Varlamov’s pad and the pipe. Of all the shots that could have gone in, that was the one that slipped through.

“I got a lucky bounce, and it went in,” Beagle said.

The Capitals have lost just one game in regulation when Beagle has scored in his NHL career. His goal opened the floodgates. The Capitals got their first power play of the game 12:21 into the period, and after a Johansson shot bounced off Varlamov’s pads, Ovechkin swatted it in. Jason Chimera made it 3-0 when he deflected in a Richards shot.

Nearly 11 minutes into the final frame, a John Carlson shot resulted in the Caps’ fifth dinged post of the night.

“We’ll save some for the playoffs, I guess,” Chimera said. “Can’t get them all in right now, so hopefully some are saved for playoffs.”