The deal is worth a total of $15.5 million, with an average cap hit of $3.875 million per season. His cap hit this season on his expiring contract is $4.2 million.
Liles has been recovering from concussion-like symptoms and is expected to return to the Toronto lineup immediately after the All-Star break.
Liles was acquired in June by Toronto general manager Brian Burke in a deal that sent a 2012 second-round pick to the Colorado Avalanche. In 34 games with the Maple Leafs, Liles has 21 points, including four goals.
"Some guys choose to go the unrestricted route, but it's a pretty special feeling when Burkie (Leafs GM Brian Burke) went out and traded for me and knowing that he wants me there for years to come," Liles said.
"As far as money goes, you could say that you leave some on the table. Maybe I did, maybe I didn't ... but I'm looking at it as I was negotiating a contract to stay in a place I wanted to be and play on a team I wanted to play on and live in a city I wanted to live in.
"It feels great. It's a place that's grown very dear to my heart, a place I was excited about getting traded to this summer."
The signing leaves the Maple Leafs with a few other decisions before the Feb. 27 trade deadline. Goalie Jonas Gustavsson is slated to become an unrestricted free agent July 1, and the Maple Leafs are expected to have contract negotiations with Gustavsson's camp, although that hasn't happened yet.
The front office also is weighing whether to trade Mikhail Grabovski, another potential unrestricted free agent. He played his best game of the season Tuesday in Toronto's win over the Islanders, but had a rough first half.
"I will say to be fair to them, not for one second was it due to a lack of effort," Burke told ESPN The Magazine. "They've worked hard from the first days of camp."
Burke would like to get bigger up front before the deadline, but understands it won't be easy.
"Guys with size who can play don't grow on trees," Burke said. "Teams that have them tend to keep them. These assets are not in play."
Craig Custance is a senior writer for ESPN The Magazine. Information from ESPN.com's Pierre LeBrun and The Associated Press was used in this report.