Madrid took advantage of Barcelona's shock loss to Deportivo La Coruna earlier on Sunday by coming from behind to win after it had looked like a dreadful Keylor Navas blunder would cost them dear.
The Santiago Bernabeu was stunned when Navas scored a bizarre own goal as he failed to deal with Antonio Sanabria's shot midway through the first half.
Cristiano Ronaldo headed in his fifth goal in four league matches before the break, but it looked for a long time like Madrid would have to settle for a draw that would have kept them behind Barca.
That was until Betis' Cristiano Piccini saw red and Ramos headed in his 10th goal of the season with nine minutes remaining to save Zinedine Zidane's men.
Madrid are now two points clear of Barca with a game in hand, having overcome a sticky spell to win their last two league games.
Ronaldo was heavily involved in the early action, having a penalty claim turned down after clashing with German Pezzella before having a left-footed effort unconvincingly saved by ex-Madrid keeper Antonio Adan.
James Rodriguez, in as one of Zidane's four changes, also tested Adan while Isco's searing drive just missed the target from 25 yards.
But, after the hosts' bright start, Navas featured in two major moments in quick succession midway through the first half.
Initially he was hugely fortunate to avoid punishment from referee Antonio Mateu Lahoz after racing out of his penalty area and taking down Darko Brasanac, the Betis midfielder furious when not even a free-kick was given after his path to goal was crudely blocked.
Then on 25 minutes, a Riza Durmisi cross from left set up Sanabria, whose low shot from 15 yards appeared to have been saved by Navas before he allowed the ball to squirm out of his grasp and knocked it over the line.
1 - Keylor Navas is the only goalkeeper to have scored an own goal in La Liga this season. Pressure.— OptaJose (@OptaJose) March 12, 2017
Madrid responded four minutes before half-time as Marcelo's cross from left found an unmarked Ronaldo, who crouched to plant in a header from eight yards and move on to 19 league goals for the season.
Aissa Mandi had a header saved by Navas after the break, while Ruben Castro fired over from a presentable chance after excellent work from Dani Ceballos to set him up.
Madrid began to find their feet when Luka Modric tested Adan and Betis needed a superb challenge from Pezzella to stop Ronaldo racing clear, but the match remained in the balance.
Zidane brought on Karim Benzema and Lucas Vazquez in place of Alvaro Morata and James for the final 20 minutes.
Ronaldo had the ball in the net but was flagged offside in a marginal call after racing on to Modric's pass, before he missed the target from a good shooting opportunity given to him by Isco's throughball a few moments later.
Betis were reduced to 10 men with 12 minutes to play when Vazquez raced clear on the counter-attack and was tugged back by Piccini, who received a second yellow card having already been booked in the first half for a foul on Marcelo.
And the winner arrived within three minutes, Ramos charging in to power home Toni Kroos' corner from eight yards.
There was one last push from Betis and Navas went some way to making up for his earlier blunder in stoppage time, a powerful header from Sanabria kept out by the Costa Rica international at full stretch as Madrid took a big step towards winning their first league title since 2012.