The judges scored it 48-47, 48-47, 49-46 for Jones (19-1). It was the champion's closest call.
Despite the loss, it was a remarkable show by the confident Swedish challenger, who had the best of the early rounds and then hung on in the fourth and fifth. And it will likely be remembered as one of the best title fights in UFC history.
"Who doesn't want a rematch," said UFC president Dana White. Jones and Gustafsson both earned US$50,000 bonuses for the fight of the night.
Still, White refused to say a rematch would be next.
Gustafsson (15-2) made the champion look human, cutting him and taking him down for the first time in his UFC career. As he promised, the Swede's hands were faster.
It wasn't until the end of the fourth round that a bloody Jones finally did damage, setting the stage for a dramatic fifth.
Both men were bleeding. Jones took Gustafsson down but the Swede fought his way back to his feet. Gustafsson looked exhausted and Jones threw everything at him, mixing elbows and kicks. Both fighters were taken to hospital after the main event.
"Thank you for everyone support," Jones tweeted after the fight. "I felt a little off my game tonight but I learned alot about myself and I promise to come back better."
In the co-main event at the Air Canada Centre, interim bantamweight title-holder Renan Barao stopped former WEC champion Eddie Wineland in spectacular fashion, finishing him with a spinning back kick to the face in the second round.
Gustafsson, wearing trunks in the blue-and-yellow colours of Sweden, walked in to Avicii's "Wake Me Up." The champion, wearing a "Not Quite Human" T-shirt, followed to the sounds of "Coming Home" by Diddy and Dirty Money as the noise level escalated in the arena.
At six foot five, the Swede had a one-inch height advantage on Jones. The champ still had a reach advantage thanks to his UFC-leading 84.5-inch wingspan, but it was only a three-inch edge this time.
Gustafsson cooly stuffed an early takedown and came at Jones, who fought back with kicks. The Swede cut the champion at the right eye midway through the first round. And with one minute left, he took Jones down for the first time in the champion's UFC career.
Jones just missed with a spinning elbow in a first round that was good for Gustafsson.
The Swede tripped Jones as he attempted a kick early in the second, only to have the champion get back up and charge at him. Jones stalked Gustafsson, who stuffed another takedown.
The crowd roared as the round ended.
Gustafsson looked to stick and move in the third while Jones looked for answers. In the fourth, Gustafsson continued to move in and out, with Jones' face showing more damage from strikes. The Swede's jab was laying waste to Jones' right eye.
A bloody Jones stunned Gustafsson with a spinning elbow and followed with a string of knees as the round counted down, leaving the Swede dazed and bloodied.
"I finally got the dogfight I was looking for," said Jones, adding he needed more work in the gym.
The win — his 10th straight — gives Jones the record for most consecutive title defences (six) in UFC light-heavyweight history. He already holds the mark for most submissions (five) by a light-heavyweight and is tied for most finishes (nine).
"He's the champ for a reason," said Gustafsson.
Wineland (20-9-1) had had a good first round but was put away soon after with Barao following the kick with several punches before referee Yves Lavigne stepped in after 35 seconds. The UFC said it was the first such spinning back kick KO in its history, earning Barao a $50,000 bonus for knockout of the night.
Barao, who has won 21 straight and not lost since April 2005 in his pro debut, danced with his cornermen in the cage after the win. The flashy Brazilian, a 7-2 favourite Saturday, may upgrade the interim belt to the real thing if champion Dominick Cruz, sidelined since October 2011 by two knee surgeries, cannot return to action come 2014.
It was a tough card for Canadian fighters, who went 2-5 on the night. Bantamweight Mitch Gagnon of Sudbury, Ont., and Montreal lightweight John (The Bull) Makdessi were the lone Canadian winners.
Rising lightweight star Khabib (The Eagle) Nurmagomedov of Russia put on a show to open the main card, using his speed and well-stocked arsenal to win a unanimous 30-27 decision over veteran Pat (Bam Bam) Healy
Healy, a big 155-pounder who was unbeaten in seven fights, had no answers for Nurmagomedov, who improved his perfect record to 21-0 and 5-0 in the UFC. At one point in the third, he slung a bloody Healy (31-16 with one no contest) over his shoulder and crossed the cage before slamming him to the canvas, bringing back memories of Matt Hughes manhandling Frank Trigg.
The Russian, who walked in with a white furry hat, used his post-fight interview in the cage to ask for a title shot.
Healy sported a close-cropped beard after being told to trim his facial hair by the Ontario Athletic Commission.
French middleweight Francis (Limitless) Carmont (22-7) improved to 6-0 in the UFC by winning a one-sided (30-27, 30-27, 30-26) decision over Costa Philippou (12-3 with one no contest). The bigger Carmont took Philippou, a former pro boxer, completely out of his game by repeatedly taking him down and dominating him on the ground. Carmont had the top position for 12:05 of the 15 minutes.
It was like women's tennis as Carmont grunted loudly each time he hit his opponent in the final seconds.
Still, White wasn't impressed by the ground war.
"Sorry I just woke up! Thank god that's over," he tweeted.
The Montreal-based Carmont, who had welterweight champion Georges St-Pierre in his corner, has won 11 straight.
Lightweight Myles (Fury) Jury improved his perfect record to 13-0 with a split decision over Montreal's Mike (The Martian) Ricci (9-4) in the final fight of the undercard. The drab contest drew loud boos from the 15,504 in attendance and did little to pump up the volume immediately before the main card. The judges scored it 29-28, 28-29, 29-28 for Jury.
"That wasn't the fight I was expecting at all!!!" tweeted White.
In contrast, Gagnon (10-2) posted a spectacular submission win over the previously unbeaten Dustin (The Diamond) Kimura. Gagnon bloodied Kimura's face with his strikes and then pulled guard when Kimura (11-1) shot in for a takedown attempt, forcing the Hawaiian to tap out to a tight guillotine choke at 4:05 of the first round.
Gagnon, returning from a one-year layoff due to knee surgery, survived an early shot to the liver and some nasty leg kicks before taking it to Kimura. The Canadian earned a $50,000 bonus for submission of the night.
Makdessi (12-2) also looked sharp in knocking out Brazil's Renee Forte (8-3) at 2:01 of the first round. Makdessi dropped Forte with a grazing right to the head and then punished him with a dozen more shots on the ground before Lavigne stepped in.
Heavyweight Brendan (The Hybrid) Schaub choked out Matt Mitrione in a battle of former football players. Schaub put Mitrione to sleep at 4:06 of the first round with a D'Arce choke.
Both fighters had pointed fingers and talked trash leading up to the bout but they hugged afterwards.
Mitrione (6-3) played six season in the NFL with the Vikings and Giants while Schaub (11-3) had a cup of coffee with the Bills and spent time in the Arena Football League.
Welterweight Stephen (Wonderboy) Thompson (8-1) knocked out Chris (The Menace) Clements of London, Ont., at 11:27 of the second round. Clements (11-5 with one no contest), in his first action since July 2012 due to shoulder surgery, saw his six-fight win streak ended. He said later he hurt his knee backstage before the show.
Brazil bantamweight Wilson Reis (17-4) used his grappling skills to control Montreal veteran Ivan (The Pride of El Salvador) Menjivar (25-11) en route to a unanimous 29-28 decision.
Michel (Tractor) Prazeres (17-1), in his first outing at lightweight, earned a split (28-29, 29-28, 29-28) decision over Jesse (The Bodysnatcher) Ronson of London, Ont. Ronson (13-3) was game in his UFC debut, but could not get his striking game going until it was too late and was outclassed on the grappling front. The loss snapped an eight-fight win streak.
Bantamweight Alex (Bruce Leroy) Caceres (9-5-0 with one no contest) used his superior striking skills to win a split (29-28, 28-29, 29-28) decision and hand Winnipeg's Roland Delorme (9-2 with one no contest) his first loss in five UFC fights.
Polish heavyweight Daniel Omielanczuk (16-3-1 with one no contest) knocked out Austrian Nandor (The Hun) Guelmino (11-5-1), a former bodyguard, at 3:18 of the third round in a battle of UFC debutantes.
The card was the UFC's fourth in Toronto and 14th in Canada.