Cristiano Ronaldo ensured Madrid went in level at the break as he rose unmarked to power home Marcelo's cross from close range for his 26th goal of the season.
And Ramos played the hero in the 80th minute - the unmarked Spain worldwide powering a patented header past Antonio Adan from a corner kick.
Luis Suarez equalised for Barcelona a minute into the second half but Deportivo had the last laugh with Alejandro Bergantinos scoring the victor in the 74th minute.
The result came four days after Barcelona hit the headlines when they staged one of the greatest comebacks in football history, overturning a 4-0 first-leg deficit against Paris St Germain to progress to the quarter-finals of the Champions League 6-5 on aggregate.
"Obviously it was hard".
"Only someone who has lived what we lived this week can understand what it means, but professionals need to know how to cope with these situations", said Luis Enrique.
Barcelona coach Luis Enrique didn't start Rafinha, Samuel Umtiti and Neymar, who was decisive on Wednesday with two goals and two assists.
Former Real Madrid youth trainee Joselu gave Deportivo a deserved lead in the 40th minute after an error from Barca goalkeeper. Barca defender Javier Mascherano failed to deal with a corner and while Marc-Andre ter Stegen managed to get his fingertips to the ball, Joselu rifled home from two yards out.
But despite what Barca's quick restart might have suggested, the goal onslaught the away team desired didn't materialise, and Mel's men were able to gather their thoughts and once again hold their foes at bay.
Arda Turan, Denis Suarez, Andre Gomes - three players you don't generally see starting for Barcelona, and today showed why. It is always better to go in euphoric than pessimistic.
But the warning wasn't heeded as centre-back Alex Bergantinos headed into the bottom corner from the resulting set piece.