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.
In the women’s Italian Open at the same atmospheric Foro Italico venue home fans were given something to shout about when Sara Errani reached the semi-finals with a superb 6-3 4-6 6-2 victory over world number two Li Na.
It was her first career win against a top-three ranked opponent and helped her reach her second consecutive Italian Open semi-final. She was joined in the semis by 11th seed Ana Ivanovic, who followed up her win over Maria Sharapova with a thrilling 6-4 3-6 6-4 win over Spain’s Carla Suarez Navarro.
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.
Top seed and defending champion Rafa Nadal faces Briton Andy Murray in the night session.
Having taken the first set Djokovic was 3-2 ahead in the second set when a brief spell of rain halted play.
Two games later the relentless Ferrer broke and went on to serve out the second set in clinical fashion.
Djokovic forged ahead in the deciding set but Ferrer refused to be subdued by the more powerful Serb, scrambling back to 3-3.
Ferrer then had a sniff of a chance in the next game but Djokovic held firm and then broke to lead 5-3.
Djokovic wobbled on his first match point, serving a double-fault but he was not phased and went on to win a punishing baseline exchange in the next point and claimed victory when Ferrer hit a tired-looking backhand wide.
(Editing by Martyn Herman)