The victory also came hours before Nadal's fellow Spaniard David Ferrer played the final match of his career, losing 6-4, 6-1 to Alexander Zverev in his last tournament before retirement.
Nadal has endured a turbulent few weeks after slipping to surprise defeats in both Monte Carlo and Barcelona last month before then being hit by a stomach bug on Sunday.
But there was never much sign of an upset in the Spanish capital, where the world number two opened up with a 6-3, 6-3 victory.
“Right now every victory is important for me because it gives me the option to play again the next day,” Nadal said.
“Two weeks ago maybe playing again was not a chance to improve because I didn't feel like that in training.
“Now I am feeling better in matches and I think every one gives me the chance to get better.”
Nadal has not arrived in Madrid without winning in either Monte Carlo or Barcelona since 2015 and, after also pulling out of Indian Wells due to a knee injury in March, concern was growing ahead of the French Open later this month.
The 32-year-old, who will be chasing his 18th Grand Slam title at Roland Garros, will now face another young talent in America's Frances Tiafoe, with either Stan Wawrinka or Kei Nishikori waiting in the quarter-finals.
“After Indian Wells, I had a big mental drop,” Nadal said. “I had to stop for two weeks and mentally I dropped.
“I struggled a lot to get fit and recover that energy, which I now feel again.”
Ferrer bowed out after losing to Zverev, calling time on a distinguished career that included 27 ATP titles and a highest ranking of number three in the world.
Former world no. 3 David Ferrer called time on his tennis career after losing to Alexander Zverev at the Madrid Open. https://t.co/fFRO8PxzN2
— Twitter Moments (@TwitterMoments) May 9, 2019
Renowned for his never-say-die attitude, the 37-year-old reached the French Open final in 2014, as well as five more Grand Slam semi-finals.
“I couldn't have given more to this sport,” said Ferrer, who left his bandana on the 'T' of the service box.
“I don't know what my legacy will be but I always fought until the last point. Maybe it will be that.”
Nishikori and Wawrinka will meet in the third round on Thursday after Nishikori took just over two hours to win 7-5, 7-5 against Bolivian qualifier Hugo Dellien and Wawrinka defeated Argentina's Guido Pella 6-3, 6-4.
The Swiss has won his last two matches against Nishikori, including a three-set victory in Rotterdam in February, when he went on to reach his first final since undergoing knee surgery in 2017.
Osaka in control
Juan Martin del Potro lost 6-3, 2-6, 7-5 to Serbia's Laslo Djere in his first match since February as the Argentine continues to work his way back from a knee injury.
Nishikori's compatriot and world number one Naomi Osaka is through to the quarter-finals of the women's tournament for the first time after she eased past Belarusian Aliaksandra Sasnovich 6-2, 6-3.
Osaka pulled out of the semi-finals in Stuttgart last month with an abdominal injury but has said she is no longer feeling discomfort during matches.
“I feel fine, so that's great,” Osaka said.
“I'm at a really good place right now. I feel like I'm having fun playing tennis again which is always a good thing for me. I always play well if I have that mentality.”
In the last eight, the two-time major champion will face Switzerland's Belinda Bencic who beat Ukrainian qualifier Kateryna Kozlova 6-0, 6-2.
A potential semi-final foe for Osaka is world number three Simona Halep, who annihilated Slovakian Viktoria Kuzmova 6-0, 6-0 in 44 minutes.
Number two seed Petra Kvitova saw off France's Caroline Garcia 6-3, 6-3 and will now face the Netherlands' Kiki Bertens.