Igor Akinfeev was Russia's hero after saving penalties from Koke and Iago Aspas as 2010 champions Spain, who dominated possession without creating clear chances, were defeated 4-3 on penalties after the game had finished 1-1.
Sergei Ignashevich became the oldest scorer of an own goal in World Cup history when the 38-year-old gave Spain an early lead at the Luzhniki Stadium.
Hosts Russia drew level in the 41st minute, Artem Dzyuba smashing home a penalty after his header was blocked by Gerard Pique's arm in the box.
Their spot-kick exit caps a tumultuous campaign for Spain, with head coach Julen Lopetegui having been dramatically sacked on the eve of the tournament and replaced with Fernando Hierro.
But Ramos was in mood to admonish his team-mates after their emotional elimination.
"We leave with our heads held high," he said, as quoted by Mundo Deportivo.
"They played to get to penalties from the start. It was the only way to do us damage.
"We hope this isn't the last World Cup for this generation. It's very tough to go out like this, with these players.
"I'm proud of them as captain because we put our souls into trying to win out there. We did everything possible."