Real Madrid cut the gap between them and Barcelona to 13 points with a morale-boosting 2-1 win over the Catalans at the Santiago Bernabeu.