Contesting his home tournament one last time before retirement, the five-time champion exchanged some warm words with Cachin at the net and gave the world number 91 a match shirt as a memento.
Nadal's reward is a last-16 clash with the 30th-seeded Jiri Lehecka on Tuesday.
"Some moments good, some moments not good. I found a way to be through. I think in the third set with some mistakes I was still able to be a bit unpredictable," Nadal said of his roller-coaster victory.
"Now I'm enjoying. Let's see how I wake up tomorrow. Playing at home means everything to me, just try my best to keep dreaming."
Since the start of the 2005 season, Nadal has lost just once in 163 matches against players ranked outside the top 50 on clay.
Cachin's two wins in Madrid this week were his first of the season, as he entered the tournament with zero wins from 11 matches contested in 2024. But those numbers do not reflect the level showcased by the 29-year-old, who saved nine out of 18 break points against Nadal, and pushed the 22-time major champion to his limits.
In a dominant first set, Nadal fired 14 winners and made just nine unforced errors to take the lead in 47 minutes.
He recovered from a double-break deficit in the second set to force a tiebreak but couldn't hold off another surge from Cachin, who converted his first chance to level the match and take it into a decider.
Nadal had two chances to go up a double break early in the final set but Cachin sidestepped both to hold and soon evened up the score at 2-2. The Argentine could not hold his level though as Nadal found an opening once again and this time did not flinch, storming through to the fourth round on Cachin's 41st unforced error of the match.