They were just 13 seconds away from a perfect game defensively through 40 minutes on Wednesday. But instead, the Avalanche’s top line and top defensive pair broke down, allowing a 2-on-0 rush on goaltender Philipp Grubauer that ended his opportunity for his fourth shutout against the San Jose Sharks.

The play started deep in the Avalanche’s zone with 22 seconds remaining. San Jose won the faceoff and caught the Avs’ top players lackadaisically backchecking, setting up an opportunity for Evander Kane to feed it to linemate Tomas Hertl, who put it past Grubauer.

That started a three-goal surge in a 9:31 span for San Jose at SAP Center, erasing a two-goal lead the Avalanche had built earlier in the second period to defeat Colorado 3-2.

The top line of Nathan MacKinnon, Gabe Landeskog and Mikko Rantanen and top blueliners Devon Toews and Cale Makar were also on the ice for the tying goal early in the third. Each of them finished minus-2. That same five-man unit was on the ice when Landeskog was called for hooking, which set up the power-play where San Jose’s Erik Karlsson scored the go-ahead tally.

“They’re on for both goals against and they took the penalty that they got the game-winner on,” Avs coach Jared Bednar said. “That group of five that plays together a lot was not good tonight. They’ve been carrying us lately and doing the bulk of the heavy lifting to win us a lot of hockey games. I just thought tonight they were a little bit off.”

MacKinnon’s 17-game road point streak was also snapped.

“They looked a little tired as a group,” Bednar continued. “They get scored on a couple of times and it was the difference in the hockey game. Our intent to check and play the right way for most of the game was good but certainly, in those couple of instances they scored on it wasn’t good enough.”

Colorado (34-13-4) trails Vegas by four points for first in the West Division and has a one-point lead on Minnesota. The Avs have a game in hand on both teams. The Wild fell 3-2 in overtime to the Golden Knights on Wednesday.

The Avs play at Vegas Monday to close out its road schedule after two games in L.A. They conclude the regular season at Ball Arena with two games against the Kings.

Forwards Tyson Jost and Andre Burakovsky scored second-period goals for the Avalanche to give them a 2-0 lead. San Jose’s comeback came just two days after Colorado erased a 3-1 deficit against the Sharks in the third period to win its third consecutive meeting between the two clubs.

“Big opportunity there to get up in the standings and we let it slip,” Jost said. “It’s not acceptable in our dressing room and we know that. We’re going to be better.”

Alex Newhook, Colorado’s 16th overall pick in the 2019 draft, made his NHL debut. Newhook, 20, signed an entry-level deal in March after a two-year stint at Boston College. He had one shot and was a plus-1 in 13:20 while centering the second line between veterans Nazem Kadri and Burakovsky.

“He made some smart puck plays, good decisions with the puck,” Bednar said of Newhook’s debut. “He didn’t have any turnovers. I thought that line was pretty good. It looked like they had a little bit of chemistry.”

At the conclusion of the game, the Avs stayed on the ice to shake long-time Sharks forward Patrick Marleau’s hand. Marleau, 41, broke the NHL record for regular-season games played two weeks ago. He appeared in his 1,776th game and 904th consecutive game — and possibly the last one ever against the Avs.

“That accomplishment is something that I still can’t even wrap my head around. How many games he’s played and how many in a row,” Bednar said of Marleau’s accomplishment, passing NHL legend Gordie Howe to break the long-standing record. “I just think it’s something I don’t see happening again. We all recognize that’s a big moment and something that’s pretty special.”

“By all accounts, Patrick Marleau is an amazing human being and an amazing teammate.”