The hosts dominated the contest and took the lead via Sidnei, but Karim Benzema converted a penalty shortly before half-time to tie things up. The pattern of play continued after the break, and former Barcelona man Cristian Tello deservedly restored the lead inside the final 10 minutes.
Los Blancos started the weekend in the lead, but Barcelona's narrow win over Real Sociedad on Saturday saw them move two points ahead of their rivals.
The visitors may have started the match as title contenders, but Real Betis were by far the better team in the first half, pressing forward and putting together several good chances. Nabil Fekir was at the heart of most of their attacking moves, while Loren Moron was a constant menace.
The striker was trouble for both friend and foe, putting his boot into a team-mate at one point:
Vinicius Jr. fired an early chance wide for Los Blancos, and Marc Bartra somehow failed to hand his side the lead, missing the target completely with an unmarked header.
Thibaut Courtois showed all of his talent with a wonder save to deny Fekir, but with five minutes left to play, the Belgian was beaten. Sergio Ramos brought down Fekir, and just as everyone anticipated a whistle for a penalty, Sidnei blasted the ball home.
It was an impressive strike:
The defender's celebrations were short-lived, however. After a half spent mostly on the back foot, Los Blancos finally ventured forward, resulting in a silly challenge from Sidnei on Marcelo. The official pointed to the spot, and Benzema converted.
It was his team's first effort on target of the half:
Despite the setback, Betis came out for the second half with the same mindset, attacking Los Blancos early and often.
It led to a massive chance after 10 minutes, with Joaquin rounding Courtois before opting not to shoot himself:
Los Blancos barely got out of their own half, and Zinedine Zidane soon decided to shake things up, taking off Toni Kroos for an extra forward in Mariano Diaz. The tactical change worked almost immediately, with Joel Robles making a great save before Ferland Mendy hit the cross bar on the follow-up.
Diaz's introduction shook things up for the hosts, who struggled to deal with the renewed energy and suddenly had to defend far more.
They still threatened, however, and Andres Guardado came agonisingly close to restoring the lead with a volley that flew wide by inches.
A mistake between Ramos and Benzema eventually gave the lead back to the Andalusians, with the ball ending up in the feet of Guardado after a poor pass. He played in Tello, who calmly converted the one-on-one.
With time running out, Madrid suddenly woke up and started to attack with intensity. Robles had a hard time controlling his box against the many players Los Blancos threw forward, and Lucas Vazquez found plenty of success out wide, firing in cross after cross.
The Andalusians held on, however, booking their biggest win of the season and greatly damaging Real's title bid in the process.
Madrid will host Eibar on Friday. Betis face local rivals Sevilla in the derby on Sunday.