Edmund beat the Serbian former world No 1 6-3, 2-6, 6-3 in the second round, making it the sixth straight tournament in which Djokovic has failed to reach the quarter-finals.
Edmund said afterwards: “I just felt good today, felt I was hitting the ball well.
“I just knew that if I put myself in the match hopefully in the closing stages I would give myself a chance.”
Djokovic played poorly in the first set but recovered to comfortably win the second. He had a chance to go up a break early in the third set but lost five straight points to allow Edmund to come back from 0-40. The unseeded Briton then broke Djokovic’s serve to go up 5-3 and easily closed out the match on his serve. Edmund added: “That game in the third set was very key. When Novak gets a lead it’s very hard to break him down because he becomes a bit more aggressive.”
Edmund next plays eighth-seeded Belgian David Goffin, who defeated Dutchman Robin Haase 7-5, 6-3.
Djokovic has struggled this year after saying he returned to action too quickly after a right elbow injury. The 12-time Grand Slam champion said: “There are obvious things that are not working well for me.
“But I have to keep working on them and pray that, and hope that, my game will get stronger.”
World No 12 Djokovic lost in the third round in Monte Carlo and in the second round in both Miami and Indian Wells. He said: “One or two points decide these kind of matches. Luck was on his side a little bit. But, also, he was courageous enough to attack the balls when it mattered and deserved to win.”
Rafael Nadal later cruised past Gael Monfils 6-3, 6-1, extending his record of consecutive sets won on clay to 48. The 16-time Grand Slam champion, coming off titles in Monte Carlo and Barcelona, has won 37 of his last 38 matches on the surface, including 20 straight.
Eighth-ranked Kevin Anderson defeated qualifier Mikhail Kukushkin 5-7, 7-6 (3), 6-2 to set up a third-round match against Philipp Kohlschreiber, who beat Roberto Bautista Agut 6-3, 4-6, 7-5.
In the women’s event, Simona Halep beat Kristyna Pliskova 6-1, 6-4 to stay on track for a third straight title in Madrid, while Caroline Wozniacki’s bid to return to the top of the rankings ended with a 6-2, 6-2 loss to 20th-ranked Kiki Bertens.
“At this tournament it’s really nice that I know I can play my best tennis,” Halep said.
World No 2 Wozniacki needed to win the title in Madrid to overtake Halep and reach the No 1 spot.