
The Serb, already qualified for November's season-ending Masters Cup, needed more than two and a half hours, overcoming 41 unforced errors and missing on a match point in the patchy effort.
The 20-year-old who won Vienna on Sunday has risen into the elite this season, claiming five titles including two Masters events, in Miami and Montreal.
The victory was a repeat of Djokovic's only previous win over the Spaniard from Roland Garros in the spring.
Djokovic next faces 2003 winner Juan Carlos Ferrero who beat old rival Carlos Moya, the 14th seed saddled with an ankle injury, 7-6 (7-2), 6-4 in the pair's 14th meeting dating to 1999 in Barcelona.
Last year's finalist Fernando Gonzalez dispatched Spain's Nicolas Almagro 7-6 (13-11), 7-5.
The fifth-seeded Chilean winner is keen to continue his progress with a place in Shanghai calling.
The South American stands provisional seventh in the chase, with four spots still open.
But the mass of ranking points on offer this week in Madrid and again in Paris at the season's concluding Masters at the Bercy arena means that performances at the two big events can make or break a player's chances.
Already qualified: Roger Federer, Rafael Nadal, Djokovic and Nikolay Davydenko, who withdrew from Madrid with an elbow injury on Tuesday, a day after reaching a Shanghai place.
Gonzalez lost to Federer in the 2006 Madrid final, then carried that momentum into January's Australian Open title match, where he again was hammered by the all-conquering Swiss.
Federer, meanwhile, was surely bearing down in training with personal spoiler Guillermo Canas looming as his Thursday opponent.
The Argentine 13th seed beat compatriot Agustin Callier 6-3, 3-6, 7-5 to set up his third meeting this season against Federer.
Canas, back since last September from a doping ban, shocked the Swiss at two straight Masters events in March, with wins in Indian Wells and Miami which left Federer momentarily reeling.
But he since recovered poise, reaching another Roland Garros final and winning a fifth straight Wimbledon and fourth consecutive US Open.
Canas owns a 3-1 record in the series.
Three more seeds were eliminated as Feliciano Lopez beat number seven David Ferrer 7-6 (7-3), 7-5, Argentine David Nalbandian put out czech number nine Tomas Berdych 4-6, 6-4, 7-6 (7-2) and Paul-Henri Mathieu stopped friend and tenth-seeded compatriot Richard Gasquet 7-6 (10-8), 7-5. By Bill Scott, dpa