Peter Horachek will cherish his first victory as head coach in the NHL — although probably not as much as the Panthers do.

The Panthers ended their nine-game losing streak with an improbable 3-2 victory over Anaheim at BB&T Center on Tuesday night.

The Ducks, despite the loss, still have the best record in the league as they have as many regulation losses as the Panthers have wins (four).

“I wasn’t sure it was ever going to end,’’ said Shawn Matthias, who started things off with a second-period goal. It feels good for everyone, we got the coach his first win. That’s a good team. We’re all happy and ready to move on to the next one.’’

The Panthers, who hadn’t won since beating the Wild in a shootout on Oct. 19, needed a win Tuesday in the worst way as they were closing in on the longest losing streak (13 games) in franchise history.

“This is not about me. This is about the team,’’ said Horachek, 1-2 since replacing the fired Kevin Dineen last week.

“The team has to learn how to win, to learn what it feels to be winners. They feel pretty good right now. They worked hard and got back in it. They needed to win a game. It had been nine of them. Winning is about the team, not individuals.’’

With the way Tuesday started, it looked like Loss No. 10 was inevitable. Anaheim, which had won five in a row, took a 1-0 lead just 40 seconds in when Andrew Cogliano froze Tim Thomas with a nice move on the doorstep and scored.

The Ducks then made it 2-0 with just over five minutes left in the period, and the Panthers heard about their lack of spark from their new coaching staff at the break.

“We have a lot of work to do,’’ Horachek said, “but I’m real proud of the way they responded against a team like that. There was a lot of heart, a lot of effort.’’

The Panthers had life when Matthias whipped a backhanded shot past goalie Frederik Andersen late in the second. Scottie Upshall followed suit a minute later to tie the score.

Florida took its first and only lead of the night 4:29 into the third when Brad Boyes followed up a shot from Upshall and knocked it through. The Panthers successfully killed off a late hooking penalty by Upshall as Thomas was strong with 32 saves.

“We’re playing better as a group, and [Tuesday] was an example of having Tim Thomas in net,’’ said Upshall, who has three goals in the past two weeks. “He’s a competitor. He lets in a goal and he gets ticked. ... He led the way. If we can follow on that, we’re going to get chances, score and be in games.’’