Antonio Sanabria scored a 94th-minute winner as Real Betis shocked Real Madrid to win at the Bernabeu in La Liga for the first time in 19 years.
The 21-year-old dived onto Antonio Barragan’s cross to head past Real Madrid goalkeeper Keylor Navas.
Zinedine Zidane’s side dominated for large spells, but Cristiano Ronaldo was among the home players to waste chances as Real produced 27 efforts on goal.
It leaves the European champions seven points adrift of leaders Barcelona.
Ronaldo, returning from a five-game ban, was making his first La Liga appearance of the season, but saw a back heel cleared off the line before Antonio Adan saved a long-range effort from the Portugal forward.
Wales forward Gareth Bale gave Ronaldo arguably the best opportunity to open the scoring with a low ball across the area, but the 32-year-old sliced over.
Luka Modric had earlier hit the side netting after a driving run from inside his own half, while Bale was denied from a clever flicked effort.
But for all the hosts’ dominance, they were left open at the back and were handed a warning when Sanabria saw his tap-in ruled out for offside late on.
Moments later the former Barcelona youngster made no mistake as Real were again caught short, scoring the winner to send Betis above their hosts to sixth in the table.
It was the first time Betis have won at the Bernabeu since Finidi George scored in a 1-0 win in October 1998 and brought to an end Real’s all-time Spanish record of scoring in 73 successive games.
Los Blancos are yet to win at home in La Liga this season, having drawn with Levante and Valencia.