Rayo Vallecano came from behind to beat Real Sociedad 3-2 away from home and claim an important victory in their fight for Primera Liga survival.