Nadal showed few signs of rustiness in his 6-1, 7-6 (4) opening win at home. He cruised in the first set and recovered in the second after twice losing his serve following a rain interruption.
The victory lasted nearly two hours, but it was fast enough to allow Nadal to watch Real Madrid's Champions League match later Wednesday night in the Spanish capital. Tournament organizers said Nadal asked to play in the afternoon so his match would not coincide with Madrid's semifinal game against Manchester City, which the hosts won 3-1 to advance to the final.
Nadal is a Madrid fan and on Saturday gave the ceremonial kickoff at the Santiago Bernabeu Stadium before the team clinched the Spanish league title with a win against Espanyol.
The fourth-ranked Nadal had been out for nearly 45 days after a rib stress fracture halted his great start to the season, highlighted by winning his record 21st Grand Slam title with victory at the Australian Open.
``Coming from injury I always need to play many matches to regain my best form,'' Nadal said. ``Winning is very important to give me confidence.''
Nadal was cruising before getting injured in the semifinals in Indian Wells, where he lost the final to Taylor Fritz for his first defeat of the season. Nadal missed tournaments in Miami, Monte Carlo and Barcelona.
The third-seeded Nadal had been downplaying expectations of winning his sixth Madrid Open title, and first since 2017.
The 35-year-old Nadal looked sharp in the first set, though, breaking serve twice against the 32nd-ranked Kecmanovic. He struggled more after the match was interrupted for about half an hour with Kecmanovic leading 1-0 in the second set as the center-court roof had to be closed. Nadal was broken twice, including while serving for the match at 6-5, but eventually prevailed in the tiebreaker by converting his first match point with an ace.
Nadal could face a quarterfinal against Spanish teenage sensation Carlos Alcaraz, and a semifinal against either top-ranked Novak Djokovic or former No. 1 Andy Murray.
If he wins in Madrid, Nadal will move level with Djokovic on a record 37 titles in Masters 1000 tournaments.
Defending champion Alexander Zverev earlier rallied past Marin Cilic 4-6, 6-4, 6-4, setting up a third-round encounter with American Sebastian Korda.
The third-ranked Zverev is seeking his first title of the season. He lost to Stefanos Tsitsipas in the Monte Carlo semifinals. Zverev also won in Madrid in 2018.
``I thought I played very well. I just lost focus in the first set,'' Zverev said. ``Marin is a difficult opponent, especially with the altitude here, so I am happy with this match.''
Tsitsipas won his opener 6-3, 6-4 against Lucas Pouille, while eighth-seeded Felix Auger-Aliassime defeated Cristian Garin 6-3, 6-0.
Qualifier Dusan Lajovic upset fifth-seeded Casper Ruud 7-6 (7), 2-6, 6-4, while ninth-seeded Cameron Norrie defeated American John Isner 6-4, 6-7 (5), 6-4.
Daniel Evans needed nearly three hours to defeat 17th-seeded Roberto Bautista Agut 6-3, 5-7, 7-6 (2).
Marc Lopez retired after losing his doubles match with Alcaraz 6-3, 3-6, 10-7 to Wesley Koolhof and Neal Skupski. Lopez, who won the Olympic doubles gold medal with Nadal in 2016, is joining the coaching staff of the Spanish great.
In the women's draw, 12th-seeded American Jessica Pegula defeated home-crowd favorite Sara Sorribes Tormo 6-4, 6-2 to set up a semifinal against with Jil Teichmann, who beat Ukrainian Anhelina Kalinina 6-3, 6-4.
Eighth-seeded Ons Jabeur made her second WTA 1000 semifinal by defeating two-time Madrid champion Simona Halep 6-3, 6-2.
``It's never easy to play Simona,'' said Jabeur, who lost to Halep in Dubai earlier this year. ``Really happy with the fact that I took my revenge. I can see that I'm progressing in my game and in other stuff. I hope I can continue with this level to play the other matches.''
The 21st-ranked Halep had 20 unforced errors and only eight winners.
Jabeur will next face Ekaterina Alexandrova, who defeated American Amanda Anisimova 6-4, 6-3.
(For more sports news and updates, follow Ahram Online Sports on Twitter at @AO_Sports and on Facebook at AhramOnlineSports.)