ORONO — Daniel Perez made Steven Swavely’s farewell speech a much more joyful occasion Saturday.

Perez, a freshman forward, punched a loose puck into the net for the winning goal in overtime, setting loose a wild celebration of Maine hockey players and 4,184 fans at Alfond Arena. The 3-2 victory over Merrimack came on Senior Night, with Swavely the last of the five Black Bear players to address the crowd in what may be his final appearance here.

“It’s a lot easier with a win,” said Swavely, the team captain, of his remarks to a throng that included 17 family members from Pennsylvania. “I had my four years here. I’m not going to sulk. I’ve been privileged to play here.”

The Black Bears (8-20-6, 5-13-2 Hockey East) seemed to have the game won in regulation, thanks in part to a Swavely goal. Trailing 2-0, Merrimack twice pulled goaltender Drew Vogler in the final minutes and got two goals, the tying one with 22 seconds remaining after a bad decision by Maine to try to shoot a puck at the empty net instead of just clearing it off the boards.

The puck was stopped at the blue line by Jared Kolquist and his subsequent shot was tipped past Maine goaltender Rob McGovern by Brett Seney, leaving the crowd in stunned silence.

During the break before overtime, Swavely cautioned his teammates: “Just get back on it. Stay positive. It’s hockey, it happens. We weren’t down, we were just regrouping and getting ready for a fresh start.”

Perez’s second career goal came 1:49 into the extra session. Fellow freshman Rob Michel put a shot on Vogler that skittered to Perez to the right of the crease. He took one whack that hit Vogler and another that sent the puck between the goaltender’s legs.

“Just kind of getting in front of the net and blind his eyes, and turned around and the puck was just sitting there and I tried to bat it in,” Perez said. “I don’t remember it going in originally but I saw the guys celebrating so I just started celebrating too, honestly. I kind of blacked out.”

After two scoreless periods, Maine got on the board at 9:48 of the third when Swavely swooped through the crease to swat a rebound past Vogler.

“I actually was trying to put in a little moving screen for (defenseman Conor Riley) and after he shot it, it just bounced right to me. It was kind of out of my reach, so I had to bring it back on my backhand,” Swavely said. “It was a blind shot in a way. But I knew I had to get it up in the air becuase the goalie was going to be sliding over and luckily it went in.”

Cam Brown made it a 2-0 lead at 14:13 when his initial shot was saved by Vogler, but he skated in from the right circle to gather the puck out front and fired it high into the net for a power-play goal.

Merrimack (9-16-7, 3-10-7) pulled Vogler for an extra attacker and got an immediate goal from Chris LeBlanc on a one-timer at 18:17 of the third before Seney’s tying mark.

All of that was moot after Perez sent the seniors and the crowd home happy.

“We wanted to send them off on the right foot, and I just tried to do whatever I could,” Perez said. “We’re happy that they’re going off winners at the Alfond, so that’s all that matters tonight.”