Tomas Kaberle and Lars Eller also scored for the Canadiens (26-32-10) who won for just the second time in their last nine games to prevent the Oilers from catching them for 28th spot in the overall standings.
Shawn Horcoff, Linus Omark and Taylor Hall replied for the Oilers (26-35-6), who have lost four of their last five outings.
Tied 2-2 after two, the Habs took the lead for good three minutes into the third period on the power play. Kaberle picked up a rebound at the side of the net and lifted a shot over Oilers goalie Nikolai Khabibulin for his third of the season.
Eller made it 4-2 just two minutes later after throwing a puck out from behind the net that caromed in off of Khabibulin.
Edmonton got back to within a goal with seven minutes to play as Hall showed some patience to outwait a defender before snapping home his 24th of the season and 50th point.
There was a mad scramble in the final minute in the Canadiens' end with the puck actually resting on the back of Montreal goalie Peter Budaj's neck at one point before being cleared. Pacioretty scored his 30th into an empty net with 17 seconds left to secure the win.
The Oilers' top-ranked power play got them on the board first with eight minutes to play in the opening period when Horcoff tipped a point shot from Corey Potter past Budaj.
The Habs tied it up with just 17 seconds left in the first on a power play of their own when Subban unleashed a bullet from the point that found its way past Khabibulin.
Montreal went up 2-1 two minutes into the second period when Scott Gomez swung around the back of the net and put a shot on target. Pacioretty swooped in to score his 29th of the season on the rebound.
The Oilers tied it back up five minutes later after a giveaway in the Montreal zone. Omark took a long shot that clipped a Canadiens defender and deflected in. It was the first goal of the season for the recent AHL call-up.
It looked like the Canadiens had gone up 3-2 with four minutes to play in the second period when Rene Bourque poked at a puck that Khabibulin had wedged between his skate and the post. The play was ruled a goal on the ice but was reversed upon a video review.
Both teams return to action on Saturday . The Canadiens play the third game of a four-game road trip in Vancouver while the Oilers travel to Colorado.
Notes: It was the second and final meeting of the season between the two teams. Edmonton won the previous match 3-1 in Montreal in November. ... The Habs have struggled on trips trough Alberta in recent years. They came into the game with four consecutive losses in Edmonton and an 0-9-0 record overall in games in Alberta since the lockout. ... Edmonton had won four straight and eight of their last nine at home against the Habs, with the lone loss in that period coming on Nov. 22, 2003. That game was played outdoors at Commonwealth Stadium. ... Montreal defenceman Andrei Markov has been cleared for contact but remains on injured reserve alongside Mike Blunden (knee surgery), Brian Gionta (biceps surgery), Mathieu Darche (upper body) and Travis Moen (upper body). ... Gomez returned after missing two games because of injury. ... Montreal lost centre David Desharnais, who left the game with a lower body injury and did not return. ... The Oilers had a healthy lineup with the exception of forward Ben Eager, who missed the match with a bout of the flu.Suggest a correction