Federer, playing in the event for the first time since 2016, beat Joao Sousa in straight sets earlier in the day.
Coric, 22, had not played since beating Cameron Norrie on Tuesday and returned superbly to race 4-0 ahead but Federer, 37, won in two hours, 31 minutes.
It was the first meeting on clay between Federer and Coric, with the SWISs leading 3-2 on previous encounters, having won the most recent 6-2 6-2 in Dubai this year.
Having lost the opening set comprehensively, during which he was treated for a blister, Federer had his first break point opportunity at 3-2 up in the second.
Though it was not taken, a magnificent cross-court forehand created another which led to a succession of exchanges of serve, culminating in another break from Federer to seal the set in 47 minutes.
The SWISs maestro saved a break point in both the fifth and nine games of the decider but a rare wayward forehand saw him slip 3-1 behind in the tie-break.
To tumultuous cheers from the crowd in the late evening, Federer, four times a beaten finalist in the tournament, rallied and served out for victory on his second match point.
He will next face eighth-seed Stefanos Tsitsipas or Italian Fabio Fognini.
Defending champion Nadal, seeking his ninth Italian title, conceded only two games in winning his two matches on Thursday.
The 32-year-old Spaniard, who has lost in the semi-finals of his last four events, took one hour eight minutes to beat France’s Jeremy Chardy 6-0 6-1 and six minutes fewer to see off Nikoloz Basilashvili of Georgia 6-1 6-0.
Nadal next plays fellow Spaniard Fernando Verdasco, who defeated 11th-seeded Russian Karen Khachanov 7-5 3-6 6-3.
World number one Djokovic, having beaten 20-year-old Denis Shapovalov 6-1 6-3 earlier in the day, needed only an hour and three minutes to oust German Philipp Kohlschreiber 6-3 6-0.
The 31-year-old Serb, who won the last of his four Italian titles in 2015, next plays seventh seed Juan Martin del Potro, who saw off Casper Ruud – the Norwegian who had progressed after Nick Kyrgios forfeited their second-round match – 6-4 6-4.