Madrid moved back to the top of LaLiga at the end of a night when it seemed everything would go against Carlo Ancelotti's side.