- Madrid player ratings: Isco 4/10, Marcelo 5/10 in loss
Honduran forward Anthony Lozano put Cadiz ahead in the 16th minute, darting between Madrid defenders Sergio Ramos and Raphael Varane to meet a cushioned header from Alvaro Negredo and lifting the ball over keeper Thibaut Courtois into the net.
Madrid coach Zinedine Zidane made four substitutions at halftime in a bid to turn the game around and brought on Luka Jovic later on, the Serbian striker soon putting the ball in the net but seeing his effort ruled out for a clear offside.
"This is a historic win and we want to celebrate it," said match-winner Lozano.
The shock victory took Cadiz up to second in the league, level on 10 points with Madrid, who visit Barcelona next week in the Clasico.
"If you concede an early goal against a team like this you really struggle," Madrid keeper Courtois said after his team suffered their first league defeat at home in more than a year.
"The first half was very bad, we conceded two or three chances, we had a serious discussion at halftime and made a few changes but couldn't find the goal because they were very organised and defended very well.
"We weren't at our best today and if you aren't at your best you can't expect to win games."
He took off Ramos at halftime and the defender was seen icing his knee as he watched on from the stands as Madrid, wearing an unfamiliar pink jersey despite playing at home, tried in vain to break down Cadiz, who are back in the top flight for the first time in 14 years.
"There's no explanation. We have to accept the defeat," Zidane said. "We can't be happy, we aren't happy, but it can happen in football. We didn't start well, it was hard for us from the beginning.
"In the second half we were a bit better, but in the first half they could have scored two or three goals. When you can't get into a game things get complicated and that's what happened tonight. There are no excuses."
On Ramos' injury, Zidane added: "Let's hope it isn't much, it's a knock, tomorrow we'll see exactly what he has."