The contract is worth $72 million total, with an average annual value of $9 million, a league source confirmed to ESPN The Magazine's Craig Custance.
The deal comes a day after a tense arbitration meeting that concluded with no agreement.
"We are very pleased to have reached a long term agreement with P.K. Subban," general manager Marc Bergevin said in a statement. "This agreement helps consolidate the future of our team. A key element of our group of young veterans, P.K. plays with a high level of intensity every time he steps onto the ice. Despite his young age, he carries a great deal of experience and brings contagious energy to the team. Defensemen of his level are a rare commodity in the NHL."
Subban, 25, took to Twitter to express his excitement about the deal.
The star defenseman is coming off the final season of a two-year, $5.75 million deal. He would have been a restricted free agent again next season if an agreement wasn't reached.
Subban had 10 goals and 43 assists -- the sixth-most points by a defenseman in the 2013-14 season -- for the Canadiens, who advanced to the Eastern Conference finals.