Spain, who won the 2010 World Cup in South Africa, finished top of Group B with 19 points, four ahead of the second-placed Swedes, who could still qualify through the playoffs in March.
"I felt more pressure now then in the Euros," said Spain manager Luis Enrique, whose side lost to eventual winners Italy on penalties in this year's European Championship semifinals.
"We tried to work a lot on the mental side, always trying to keep it positive and the players responded well. I'm so proud of them and how they responded."
Spain, playing in front of 52,000 fans in the sold-out La Cartuja stadium, had never lost a home game in World Cup qualifiers and kept their record intact in Seville.
They had only ever lost four of 52 games in the city.
"We knew it was a life and death situation and we wanted to qualify at any cost. Nobody said it was going to be easy and I'm happy for our people," Sergio Busquets told reporters.
"It feels sour. I think we played a good first half and created chances, but the ball did not want to go in. It was not our day." Forsberg told reporters.
After playing the full 90 minutes in Sweden's 2-0 loss to Georgia on Thursday, Zlatan Ibrahimovic started on the bench and made little impact when he came on for the last 20 minutes.
The game looked to be heading for a draw, which would have been enough to take Spain to the finals, when Olmo's stunning strike rebounded off the woodwork to Morata, who had come on just before the hour mark, and he calmly put the ball in net.
It will be Spain's 16th appearance in 22 World Cups and the last time they failed to qualify was in 1974.