Real Madrid survived a late scare from Granada to go four points clear at the top of La Liga.
Karim Benzema, Eden Hazard and Luka Modric appeared to have set Madrid on their way to an easy victory before two strikes from the visitors.
James Rodriguez scored at the death to secure the points and bring relief to the Bernabeu.