Elsewhere, Britain's Andy Murray (fatigue) and defending women's champion Serena Williams (elbow) withdrew, while men's defending champion Novak Djokovic was put through his paces before ousting big-hitting Brazilian qualifier Thomaz Bellucci 5-7, 6-2, 6-3 to set up a quarter-final meeting with Japanese fifth see Kei Nishikori.
Federer, bidding to win his first title on the red clay of the Foro Italico, swept Anderson aside 6-3 in the first set and looked to be heading to an easy win on Centre Court before the 15th-seeded South African launched a late fightback.
Anderson stubbornly saved two match points in the second set before Federer sealed the win 7-5 to book a last eight clash with Tomas Berdych, who ended the hopes of local hope Fabio Fognini in a thrilling contest won 6-3, 3-6, 7-6 (7/2) by the Czech.
If Federer accounts for Berdych he will meet seven-time champion Nadal – a 6-4, 6-4 winner over big-serving American John Isner — in the semi-finals on Saturday, providing the Spaniard overcomes Swiss Stan Wawrinka on Friday.
Nadal came into the event looking to make amends for his defeat to Murray in the final of the Madrid Masters last week, when the Scot took his victory streak to a remarkable 10 wins out of 10 on clay this season.
The Spaniard said he is “more than happy” as he looks to put the mediocre form that has besieged his clay court game lately behind him as he ups the tempo ahead of bidding for a 10th French Open title at Roland Garros.
“I'm more than happy, I think I played a fantastic match against a very, very tough opponent,” said Nadal.
Nadal, however, said his form on the red dirt so far this season means he won't be the bookies' favourite.
He added: “This year for sure I haven't been consistent enough to be considered the main favourite for Roland Garros.”
– Murray pulls out –
Murray's hopes of continuing his stunning form on what is not his favourite surface were kept in check by a bout of fatigue which forced the Scot, the world number three, to pull out prior to his third round match-up with Belgian David Goffin.
Goffin will now meet David Ferrer after the Spaniard beat countryman Guillermo Garcia-Lopez 6-1, 6-3.
“I'm going to take a few days' rest, not go on the court,” said Murray, who added that his decision was a precaution with the French Open looming.
“It wasn't just about today's match. It was about the rest of the tournament… and further down the line the possibility of getting sick and missing five, six or seven days.”
Joining Murray was defending women's champion Williams, who cited a sore right elbow for her decision to withdraw prior to her third round match with Christina McHale.
Williams, who exited the Madrid Masters in the semi-finals last week, said the ramifications for her future targets of Roland Garros and Wimbledon were too serious had she decided to play through the pain.
“It wasn't an easy decision, I talked with my coach and he said it wouldn't be smart for me to play,” said Williams.
Her absence has paved the way for Russian Maria Sharapova, who won the last of her two Rome titles in 2012, to aim for a third Italian Open crown.
Sharapova cruised past Bojana Jovanovski of Serbia 6-3, 6-3 to set up a quarter-final with Carla Suarez after the Spanish 10th seed took three sets to beat Eugenie Bouchard of Canada.
On her way to the final the Russian could cross paths with Romanian second seed Simona Halep, a straight sets winner over Venus Williams 6-2, 6-1 or Czech Petra Kvitova, who swept Jelena Jankovic of Serbia aside 6-3, 6-2.