Spain were awarded a second penalty just over 20 minutes later, with Alvaro Morata stepping up to double the home side's lead, before Mikel Oyarzabal secured all three points in the 87th minute.
With a maximum 12 points from four matches, the result means Spain are five clear of Sweden and Romania at the top of Group F. They disappointed in the Nations League, before registering unconvincing wins against Norway and Malta to kick off qualifying, and even their 4-1 win against the Faroe Islands last time out left a lot to be desired with regards to their performance.
Spain thought they had taken the lead in the first half when striker Rodrigo converted a cross by Valencia teammate Dani Parejo from close range but the goal was wrongly ruled out for offside as video technology is not used in the qualifiers.More news: US formally asks UK to extradite WikiLeaks' Assange
Spain's coach Luis Enrique was not present at the match for personal reasons, but after the match members of the team expressed pride that they had been able to win one for him.
The hosts continued to wear the dogged Swedes down and they got their breakthrough when visiting defender Sebastian Larsson's outstretched arm blocked the ball and Ramos calmly deceived keeper Robin Olsen to convert from the spot.
Morata's penalty kick came after he was tripped by Filip Helander. Ramos converted the first penalty, before showing his first-class leadership skills in allowing Morata - low on confidence after a reasonably poor season - to take the second.More news: Australia fight back to beat Brazil 3-2
Spain bring a 4-match winning streak in all competitions into this fixture having accounted for the likes of Bosnia-Herzegovina, Norway, Malta and Faroe Islands - the latter three results being in these Euro 2020 qualifiers along with a friendly worldwide win against Bosnia.
"This is an abnormal situation but at least we've managed to give a win to our coach".
The skipper recorded his maiden win in his debut appearance some 14 years ago, on 26 March 2005, in a 3-0 triumph over China.More news: Report sent to Trump says Kellyanne Conway should be fired