World number four Raonic threw the kitchen sink at the elastic-limbed Serb for two hours and 14 minutes, striking 42 winners and 14 aces but Djokovic, aiming for a fifth consecutive title at the year-ender, was equal to everything -- just.
It has been missing for a while but Novak Djokovic rediscovered his warrior spirit to tame Canada's Milos Raonic 7-6(6), 7-6(5) in a rivetting duel and guarantee progress from his group at the ATP World Tour Finals in London on Tuesday.
The 29-year-old Serb's recent malaise has cost him the world number one ranking he held for 122 weeks but when backed into a corner by an inspired Raonic, he responded in the belligerent manner that has earned him 12 Grand Slam titles.
World number four Raonic threw the kitchen sink at the elastic-limbed Serb for two hours and 14 minutes, striking 42 winners and 14 aces but Djokovic, aiming for a fifth consecutive title at the year-ender, was equal to everything -- just.
Having edged a high-intensity first-set when Raonic double-faulted on set point in a tense tiebreak, Djokovic looked to have broken the shackles in the second to lead 4-2.
Raonic, who dialled up his mighty serve to speeds of 140mph, stormed back to rock Djokovic on his heels and came within a missed forehand of extending the match into a decider.
But Djokovic produced a magical backhand flick at 5-5 in the night's second tiebreak, then an ace, before Raonic succumbed to an eighth successive defeat at the hands of the Serb when his backhand flew wide.
With two wins in the bag Djokovic, whose form has tailed off since winning the French Open in June, is now assured of a semi-final spot although with 200 ranking points up for grabs in his final group match against Gael Monfils he will not be letting up.
Raonic will be favourite to beat Dominic Thiem and reach the semis too, although the Austrian will be heartened by his 6-3, 1-6, 6-4 defeat of fellow debutant Monfils earlier.
"I managed to hang in there mentally and stay strong and believed that the opportunities would come," Djokovic, who needs to better Andy Murray's performance here to reclaim the number one ranking, said.
"It could have gone either way this match. He's such a strong player and has got firepower.
"Two tiebreaks against a big server is a great win."
Despite having won only one set in their previous seven matches, Raonic betrayed no inferiority and forced Djokovic to save three break points early on.
Wimbledon runner-up Raonic was the aggressor throughout the opener while Djokovic absorbed the blows and waited to strike.
Raonic did little wrong but was punished for not putting away a volley when leading 3-2 in the tiebreak and at 5-5 Djokovic produced a backhand lob of rare quality.
The Canadian saved a set point with a barrage of bludgeoning forehands that cracked Djokovic's defences but then self-destructed, shanking a forehand return off a powder puff second serve before offering up a double fault.
Djokovic was twice pegged back after breaking in the second set and had Raonic converted the set point that came his way when Djokovic tugged a backhand long at 5-6, the Canadian powerhouse might have taken some stopping.
It was not to be though as Djokovic wriggled out of trouble to keep the pressure on Murray in the race to end the year as top dog for the fifth time in six seasons.
"I could have won it, I gave myself the chances," Raonic, who won 83 points to Djokovic's 85, said. "I did a lot of good things. A lot of things to be proud of."
Earlier, 23-year-old Thiem withstood a fightback from the mercurial Monfils to become the first Austrian to win a match at the event since Thomas Muster in 1996.