– The angle wasn’t pretty.

Wild winger Tyler Ennis was at the top of the left faceoff circle with his back to the net and his skates approaching the goal line.

But he still heaved a backhander at Sabres goalie Chad Johnson.

And it turned out to be the right decision, as the puck went in — a bizarre goal that fit perfectly in an unpolished effort from both teams ripe with defensive lapses and choppy play that had the Wild narrowly holding off the Sabres 5-4 Wednesday in front of 17,418 at KeyBank Center.

“It was an ugly game on both sides,” Wild coach Bruce Boudreau said. “But I think we persevered.”

Ennis’ goal 8 minutes, 59 seconds into the first period tied the score at 1, his first goal in 10 games. What made the goal extra meaningful was it came in his return to Buffalo — he and winger Marcus Foligno were flipped from the Sabres to the Wild during the offseason as part of a four-player trade that sent winger Jason Pominville and defenseman Marco Scandella the other way.

“It was a good feeling,” Ennis said. “Good memories here, and it was good to win in this building again.”

Earlier in the period, Pominville jammed at the puck at the post before center Jack Eichel finally got it to trickle past goalie Devan Dubnyk at 6:55.

The play was reviewed, after initially being called no goal, but ended up counting.

That seemed to spark the Wild.

After Ennis’ tally, the Wild grabbed the lead at 12:28 when winger Mikael Granlund finished off a two-on-one rush by wiring a shot by Johnson. Only two minutes later, winger Nino Niederreiter upped the Wild’s lead to 3-1 after he tipped a Mikko Koivu shot on the power play to extend his goal-scoring streak to five games.

At the first intermission, the Sabres pulled Johnson after a 10-save showing and replaced him with Robin Lehner, who totaled 17 saves, and the change appeared to galvanize the Sabres.

They controlled the start of the second and trimmed their deficit only 2:01 into the period when winger Jordan Nolan’s shot caromed off defenseman Jonas Brodin and froze Dubnyk.

Buffalo continued to press and looked close to finding the equalizer before Niederreiter snuffed out that momentum. He one-timed a behind-the-net pass from center Eric Staal at the post by Lehner to reinstate the Wild’s two-goal lead at 7:57 and extend his power-play goal streak to four games. Niederreiter also has eight points during his seven-game point streak.

“Just trying to go to the net and get some greasy goals,” Niederreiter said. “Fortunately, they’re going in right now.”

That cushion grew to three goals with another power-play tally, this one from Granlund after he tipped a Koivu shot with 4:04 remaining in the second. The unit went 2-for-3, while the penalty kill was 3-for-3.

Granlund now has four goals in his past two games and boasts nine points during a five-game point streak.

Granlund’s second goal turned out to be vital, because the Sabres made it 5-3 at 18:25 on a deflection by winger Sam Reinhart, then pulled within one at 13:55 of the third period after a Nolan shot slipped through Dubnyk, who finished with 30 saves.

It was a sloppy finish that didn’t undermine the Wild but one that certainly revealed how slim the margin of error was against the worst team in the Eastern Conference (5-13-4).

“If I had an answer on how to avoid sloppiness in a game,” Boudreau said, “I’d be a lot richer than I am.”