The Spanish star had been sidelined with a rib injury since his Indian Wells final defeat in March but showed little sign of rust as he skipped into the third round.
The 22-year-old Kecmanovic entered the match carrying the second-highest tally of wins on tour this season –- his 23 victories placing him just one behind Andrey Rublev, Stefanos Tsitsipas and Carlos Alcaraz.
Nadal, a three-time title winner in 2022, improved to 21-1 for the year and now awaits the winner of the clash between Belgian qualifier David Goffin and Dutchman Botic van de Zandschulp.
After a fairly routine opening set and a brief rain delay, Nadal faced significant resistance from the world number 32, who was broken in game five of the second set but struck back immediately as he started to find his range from the baseline.
Nadal found an opening at 5-5 and broke on his first opportunity, thanks to a long backhand from Kecmanovic. The number three seed could not serve out the win though, dropping serve as Kecmanovic forced a tie-break.
The pair were neck and neck, gifting each other mini-breaks before Nadal finally secured the win in just under two hours with an ace.
Second-seeded Alexander Zverev began his title defence with a hard-fought 4-6, 6-4, 6-4 win over former US Open champion Marin Cilic.
The German is a two-time Madrid champion and now owns a 16-2 win-loss record at the Caja Magica.
Earlier on centre court, Ons Jabeur marched into the women’s semi-finals with a crushing 6-3, 6-2 win over former world number one Simona Halep.
After avenging her Charleston final defeat to Belinda Bencic in the previous round, the Tunisian world number 10 reversed her result against Halep from Dubai three months ago, sweeping the Romanian aside in just 67 minutes.
The first ever Arab tennis player to crack the top 10, Jabeur is through to the second WTA 1000 semi-final of her career where she faces Russian Ekaterina Alexandrova.
“Simona, it’s never easy to play against her, she’s a great champion, she was number one, a Grand Slam champion,” said the 27-year-old Jabeur, who is now 2-2 against Halep in their head-to-head.
“I was more aggressive this time, physically much better on the court. My drop shot helped me a lot today. I’m very happy with the attitude today, so hopefully we’ll continue with this level.”
Halep drew first blood, inching ahead 2-1 but Jabeur scooped the next three games and sealed the set with a flashy point that ended with a forehand down-the-line winner.
Jabeur continued to pepper Halep with her signature drop shot, earning two breaks in the second set en route to a convincing victory.