When the Soviet hockey team left Madison Square Garden Thursday night, it padlocked three dressing rooms, making life difficult for athletes competing in the Millrose Games. What may have been stored inside were secret weapons, because today the Soviets made life very distressing for the National Hockey League.

Rallying from a two-goal deficit late in the second period the Soviets earned a 5-4 victory over the NHL All- Stars to tie the Challenge Cup series and make Sunday night's third game rank as the hockey comfrontation of the millennium.

Until Colorado's Barry Beck rammed Alexander Skvortsov into the boards and drew a minor penalty with 4:53 left in the second period, the NHL was in control. But Boris Mikhailov scored five seconds before the penalty expired and 45 sconds later Sergei Kapustin created a 4-4 tie.

Vladimir Golikov produced the winner at 1:31 of the third period. Sergei Makarov faked defenseman Denis Potvin of the Islanders out of his path and fired at goalie Ken Dryden from the right-wing circle. Golikov beat defender Guy Lapointe of Montreal to the rebound and flipped it past Dryden.

The Soviets managed to break up most of the NHL plays throughout the remainder of the game, although the visitors received a monumental scare with 2:40 to play.

The Islanders' Bryan Trottier attempted to skate around a pileup in front. If he had succeeded, he would have been looking at an empty net, but goalie Vladislav Tretiak dove out to smother the puck.

The NHL yanked Dryden for a sixth forward with 39 seconds left and twice forced faceoffs in the Soviet end. With 18 seconds remaining, Philadelphia's Bobby Clarke lost the draw to Vladimir Petrov. With nine seconds left, Clarke pulled the puck back to Guy Lafleur at the right point, but Lafleur's shot was deflected and Tretiak easily turned aside a routine effort by Potvin with two seconds on the clock.

The Soviets were late to Friday's practice because Tretiak overslept. It seemed that he was still slumbering for 25 minutes today, as four of the NHL's first seven shots went behind him.

Kapustin gave the Soviets an early lead on a fine cross-slot pass from Sergei Starikov. Then Viktor Dombrovski, the Russian referee, nailed Soviet winger Vladimir Kovin with the game's first penalty, for cross-checking Trottier, and Mike Bossy converted with a soft goal off Tretiak's pad.

Trottier made it 2-1 late in the first period, taking Islander Clark Gillies' long pass from the right-wing boards and beating Tretiak while being held by Basili Porvukhin.

When Buffalo's Gil Perreault made it 3-1 at the 27-second mark of the second period, the NHL folks could taste the champagne. Perreault came down the left side, faked defenseman Valeri Vesilyev out of his path and drilled the puck through Tretiak.

Mikhail Varnakov pulled the Soviets within 3-2 on a classic move. Skating in from the right-wing boards, he lured Montreal's Larry Robinson one way and Dryden another, then flipped a backhander over the goalie.

Robinson recouped by sweeping down the left side and taking Lafleur's artful pass around Starikov for a 4-2 edge.

The NHL seemed headed for the clinching victory until Beck's assault, which sent Skvortsov to the bench with a big welt on his forehead.NHL Coach Scotty Bowman termed it "a marginal call, I think everyone knows that" by Dombrovski, but in truth Beck's mother probably would have signaled a foul. Mikhailov then collected a Petrov pass and shoved the puck behind Dryden before his guardian, Lapointe, could move.

The NHL still was grousing about the penalty when Viktor Zhluktov gained a rare faceoff decision over Clarke in the NHL and Kapustin knocked the puck past an off-balance Dryden.

Viktor Tikhonov, the Soviet coach, said his team won because "the whole team of ours played, as compared to the first game, when two of our lines did not play well."

This time the Soviets forechecked adeptly, keeping pressure in the NHL end and courageously accepting stiff checks to make good passes. The 31-16 margin in shots was a true indicator of the play and except for Tretiak's poor start it probably would have been no contest.

"They played about as perfect a game as a hockey team can," Bowman said. "They made us look bad. They made us play the way we did. They took away the quick break out of our end and they ran their defensemen high along the boards. They were keeping the puck in our end."

There was a five-minute delay after the first shift, while each coach waited for the other to ice his second line. The Soviets were given last change as the home team today, but nobody had told Bowman, who was given the home lineup sheet before the game.

"I didn't realize we were alternating, but I really don't think that was a factor," Bowman said.

Neither was Dombrovski's officiating and the referee should not affect the outcome of Sunday night's grand finale, either. Fortunately, the referee for the biggest of hockey games is the NHL's best, Andy Van Hellemond.

The pressure, for Van Hellemond and the players, is enormous. For hockey fans, it should be an unforgettable treat.