Los Blancos found themselves behind on 25 minutes when Keylor Navas squirmed Antonio Sanabria shot into the net.
Cristiano Ronaldo drew the hosts level four minutes before half-time when helped Marcelo’s cross on into the bottom corner.
Cristiano Piccini was sent off for a second bookable offence on 78 minutes and three minutes later Ramos secured a vital three points for Madrid, heading powerfully past Antonio Adán.
Madrid out the blocks quickly
Zinedine Zidane’s side managed to book their place in the quarter finals of the Champions League earlier in the week, and began the game in blistering fashion.
Ronaldo couldn’t keep his shot down on seven minutes, but was denied the game's opener soon after when his low shot was pushed round the post by Adán.
Madrid continued on top and Isco curled inches wide of the post on 13 minutes before the hosts could have found themselves down to 10 men.
Darko Brašanac found himself baring down on goal and Navas came out of his area, completely missed the ball and brought down the midfielder but nothing was given.
Betis break deadlock midway through first-half
Betis, who last won at the Bernabéu in 1981, would have felt aggrieved by the decision, however, they were handed a gift four minutes later as a moment to forget for the Madrid ‘keeper gifted them the lead.
Sanabria forced a low save from the Costa Rican, who managed to let the ball squirm out out his grasp and into his own net – becoming the first ‘keeper in La Liga this season to score an own goal.
Real almost put the blunder directly behind them, but an unmarked Ramos volleyed over inside the area.
Ronaldo heads hosts level before half-time
Madrid continued their pressure and drew level four minutes before half-time when they made the most of a swift counter-attack.
Marcelo’s cross from the flank picked out an unmarked Ronaldo, who guided his header past Adán and into the bottom corner for his 18th La Liga goal of the campaign.
Betis began the second-half well and came close when Aïssa Mandi’s header down was saved low by Navas.
Dani Ceballos’ pull-back was fired over the bar by Rubén Castro before Luka Modrić was denied low by Adán at his near post.
Ronaldo was denied his second goal of the game on 72 minutes when he lofted over the Betis 'keeper, but was adjudged to have been offside.
Ramos heads late winner after Betis red card
The visitors were down to 10 men six minutes later when substitute Lucas Vázquez was hauled down by Piccini, who received his marching orders after picking up his second yellow card.
Madrid made the most of their extra man advantage and managed to take the lead for the first time in the game just three minutes later.
Toni Kroos’ corner found the head of Madrid captain Ramos, who got to the ball ahead of his marker and headed home for his 10th goal of the season and his second in as many games after netting against Napoli in the Champions League on Tuesday.
Navas produced a match-winning save in the second minute of additional time when he plucked Sanabria’s header from the bottom corner, ensuring Real Madrid moved back into first.