The Serb looked to be in full control when he led 5-2 in the opening set but Spaniard Ferrer fought back to 5-5 and although he lost the opener the tone was set for an intense duel.
Djokovic eventually prevailed on his second match point having double-faulted on his first, the point in between being a 38-stroke baseline rally of extraordinary quality.
Djokovic will face Milos Raonic in the semi-finals after the Canadian beat Roger Federer’s conqueror Frenchman Jeremy Chardy.
On the other side of the draw Grigor Dimitrov reached his first masters Series semi-final when German veteran Tommy Haas retired from their match with a shoulder injury.
Celebrating his 23rd birthday Dimitrov was presented with a cake on the court which his coach Roger Rasheed splatted all over the Bulgarian’s face.
“It was one of the most memorable days of my life,” said Dimitrov. “I was just talking to my team, it’s my first win on my birthday, so it feels good. It’s a bit unfortunate, the way it ended up. But I’m just a happy birthday boy today.”
In the women’s Italian Open at the same atmospheric Foro Italico venue top seed Serena Williams breezed past Shuai Zhang 6-1, 6-3 in a one-sided contest.
The American roared out of the traps, winning five games in a row and crushing any chance of resistance from the Chinese.
Zhang raised her game towards the end of the first set and made a decent fist of the second, but Williams’s driving forehand and serving power was too much for the world No 43.
Williams will get the chance to avenge her Australian Open defeat to Ana Ivanovic in the semis after the Serbian 11th seed followed up her impressive win over Maria Sharapova with a thrilling 6-4, 3-6, 6-4 win over Spain’s Carla Suarez Navarro.
Meanwhile, last night’s quarter-final between Andy Murray and world No 1 Rafael Nadal was shaping up as a classic.
A near flawless display of tennis saw Murray take the first set 6-1, before Nadal regrouped to take the second 6-3 and force a decider.