Santiago Solari's side, who were missing seven first-team players and lost Karim Benzema to injury at the end of the first half, were pegged back by former forward Sergio Canales who levelled in the 67th minute with a scrappy finish through the legs of stand-in goalkeeper Keylor Navas.
The goal, awarded after a video assistant referee (VAR) consultation, looked set to pour more misery on the misfiring European champions who drew with Villarreal and lost to Real Sociedad in their first two games of 2019.
But substitute Ceballos, a former Betis player, secured a vital win with two minutes remaining, sending his free kick outside the Betis wall and into the corner, prompting boos from his old club's supporters and relieved celebrations from his team mates.
The victory took Real Madrid above Alaves and into fourth place on 33 points, although they are still 10 points behind leaders Barcelona who beat Eibar 3-0. (Reporting by Richard Martin, editing by Ed Osmond)
(This story has not been edited by Devdiscourse staff and is auto-generated from a syndicated feed.)