It wasn’t pretty by any means, but the Sharks managed to get a vital two points to stay in the race for the Pacific Division title with a 5-4 win over Edmonton on Tuesday night at SAP Center.

The Oilers erased a 3-1 deficit to take a 4-3 third period lead. Jordan Eberle’s pass was knocked away by Matt Irwin, but ended up on second-year forward Ryan Nugent-Hopkins’ stick. He turned around and beat Antti Niemi’s cleanly for his second goal of the game at 6:16.

The Sharks’ top line tied it, though. While nearly falling flat on his face, Joe Pavelski managed to reverse-kick the puck to an open Joe Thornton at the side of the cage. The captain quickly found Brent Burns on the other side for an easy slam-dunk at 10:35.

After looking dangerous all night but having nothing to show for it, the top power play unit finally came through when David Perron went off on a tripping minor. Burns flubbed a one-timer at the point, but the puck squirted to Patrick Marleau, who backhanded in his 32nd goal at 12:31. That held up as the game-winner.

The Sharks (48-20-9, 103 points) are one point behind Anaheim. The Ducks, who host the Oilers on Wednesday, have two games in hand and have clinched the tiebreaker of more regulation/overtime wins.

Edmonton erased a 3-1 hole with two second period goals just 38 seconds apart.

First, Nugent-Hopkins curled toward the top of the circle from the wall, and beat Niemi to the short side with a wrist shot at 13:04. He helped tied the game soon after by driving the net on a rush with Eberle, who skated past Brad Stuart and centered the puck, which deflected in off of Justin Braun’s skate with Nugent-Hopkins in the crease.

The Sharks opened the scoring early with a goal from the fourth line. Tyler Kennedy’s shot rebounded to Andrew Desjardins, who flipped it past Ben Scrivens at 3:11. Desjardins’ goal, his third, was his first since Jan 9 vs. Detroit, 31 games ago.

Edmonton tied it with a power play goal, when Taylor Hall’s wrist shot sailed just inside the far post at 12:34 of the first.

San Jose regained its lead later in the period, though, with Dan Boyle’s third goal in as many games. Thornton started it by winning a faceoff, driving through Anton Lander and giving Boyle a perfect pass. Boyle picked the top corner at 15:54.