The European champions had luck on their side after an early Keylor Navas howler handed Alaves’ Deyverson a simple tap in for the opener.
Ronaldo levelled from the penalty spot after Deyverson was penalised for diverting a Gareth Bale free-kick wide with his outstretched hand.
Real and Ronaldo’s second was more like the three-time World Player of the Year of old as he drove towards the Alaves goal before his shot from 20 yards out deflected into the far corner.
Zinedine Zidane’s men were grateful to Navas when he redeemed himself with a brilliant save from Victor Camarasa at the start of the second-half.
Ronaldo had the chance to seal his hat-trick when the visitors were handed another penalty 12 minutes from time.
This time, though, his low effort was saved by Fernando Pacheco before Alvaro Morata came off the bench to lob home Real’s third.
However, Ronaldo wasn’t to be denied his hat-trick as he blasted home after a neat one-two with Marcelo two minutes from time.