Unseeded British player Kyle Edmund recovered from a second-set lapse to defeat Djokovic, 6-3, 2-6, 6-3.
Djokovic, a two-time champion in the Spanish capital, has not won a deciding set this year and, having previously suffered final set losses to Martin Klizan, Dominic Thiem and Taro Daniel, the 30-year-old Serb's disappointing run continued.
Djokovic stormed through the second set on the Manolo Santana court and, at his best, might never have looked back, but he spurned three break points early in the decider and Edmund pounced to win 6-3, 2-6, 6-3.
"But I have to keep working on them and pray that - and hope that my game will get stronger, get better as definitely as the matches. go the distance".
World No. 1 Rafa Nadal recorded his 20th straight win on clay as he began his quest for a sixth title in Madrid, defeating Frenchman Gael Monfils 6-3, 6-1.
Edmund made the ideal start with a break of serve in the opening game of the match and although Djokovic immediately hit back, Edmund broke twice more to take the first set.
"There are obvious things that are not working well for me".
The world number 12 served out the set, but was left frustrated when a tenacious Edmund rallied from 0-40 down to hold and take a 3-2 lead, leaving Djokovic to rue unforced errors when his opponent was up against it.
"I was looking forward to these kind of matches, looking to try to win these kind of matches".
World number one and top seed Simona Halep had earlier maintained her charge towards a third consecutive Madrid title as she eased past Kristyna Pliskova 6-1, 6-4. Obviously, I've played this sport so many years and had a bunch of success.
"I haven't had an easy draw here, but I don't think anyone has". That game in the third set was very key.
'At the same time, you know, nobody is forcing me to play this sport.
The second-ranked Wozniacki needed to win the title in Madrid to overcome Halep for the No. 1 spot. The former world No.1 has not played a competitive match since Wimbledon last summer and aborted comeback attempts at the US Open and Australian Open in January after which he had surgery in Melbourne.
In the women's tournament, Maria Sharapova reached the quarter-finals with an impressive 6-3, 6-4 demolition of France's Kristina Mladenovic.