Real Madrid survived a scare to beat Rayo Vallecano, while there were victories for Real Sociedad and Almeria in the Primera Liga on Saturday.