But Rafael Nadal, like Djokovic a former champion at the event, was unable to escape an on-form Kei Nishikori as the fourth seed sent out the Spaniard 6-2, 6-4 thanks in part to six double-faults from Nadal.
The red-hot Nishikori is riding a wave of momentum from his hardcourt title last week in Washington and will next face second seed Andy Murray who beat French 10th-seeded holder Jo-Wilfried Tsonga 6-4, 6-4 and took revenge for a semi-final loss a year ago in Canada.
Nishikori won his first match against Nadal after seven losses, taking just under 90 minutes to advance in his best Canadian showing.
“It took a long time to finally beat him, but I’m very happy to win my first match against Rafael,” said Nishikori.
“I knew I have to be aggressive, so I have to change some tactics to play against Rafa.
“Everything was feeling well today. I felt like everything was going in.
“I mean, he’s still not maybe 100 per cent, but he’s Rafa.”
Seventh seed Nadal was playing in Canada for the first time since winning his third title here in 2013 and he now stands 28-7 in the country.
Djokovic found himself down a set and a break against Gulbis.
Gulbis, whose career best was a Roland Garros semi-final in 2014, has since gone into a funk in 2015.
But he forced his world number one to save two match points in the second-set tiebreaker of a thriller lasting two and a half hours.
Djokovic levelled at a set apiece and re-established order as he ran away with the third set for the win.
“Ernests was a better player for two sets — unfortunately he missed two match points,” Djkovic said.
‘Muscle it out’
“I wasn’t very happy with my game. But you have to muscle it out sometimes and I had to put in the effort.
“One day you play well, the other you don’t. It’s important to stay committed to every point, believe, fight. That’s what gets you out of trouble.”
Djokovic is bidding for his fourth Canadian title and the win puts him into a semi-final against unseeded Jeremy Chardy.
Chardy booked his first career appearance in the semi-final of an ATP Masters 1000 event, struggling for three hours to defeat John Isner 6-7 (9/11), 7-6 (15/13), 7-6 (7/4).
Chardy overcame 32 aces from the big American to reach the final four.
The match, which began two hours late due to rain, lasted three hours and eight minutes.
“I’m very proud to reach my first Masters semi-final,” said the 49th-ranked winner who levelled his season record at 18-18. “I was lucky to come back in the second.
“I’m really happy. I stayed really focused and really strong in my head the whole match.”
Chardy advanced with 12 aces and a single break of serve while saving break points on six of seven occasions.
The Frenchman has cast a spell over Isner in their career meetings, winning all four of their matches including at Roland Garros in the second round in May.