Chile’s victory — through goals from Eduardo Vargas and Charles Arranguiz — made the South Americans and the Netherlands the first teams to go through to the second round.
After a golden era that saw them win the European Championships in 2008 and 2012 and the World Cup in 2010, Spain have suffered a dramatic fall from grace.
They equalled Italy’s unwanted record in 1950 of being booted out of the World Cup after just two games.
It was Chile’s first win over the Spanish in 11 meetings.
Spain’s confidence seemed to have evaporated after their 5-1 defeat to the Netherlands in their first Group B game on Friday.
Coach Vicente del Bosque dropped established stars Gerard Pique and Xavi Hernandez but it had no impact in the charged atmosphere of Rio de Janeiro’s Maracana stadium.
Chile pressed forward from the start. Vargas’ shot in the second minute was narrowly deflected wide of the goal by a defender.
Spain also pushed up, but errors soon proved costly.
Xabi Alonso gave the ball away in the 20th minute and the ball reached Arranguiz in the penalty area who slipped it inside to Vargas who smashed the ball past Spain’s captain Iker Casillas, making a Spanish record 17th appearance in a World Cup finals match.
The game carried on at a furious pace as the defending champions sought a way back into the game.
But in the 43rd minute, Casillas clumsily punched away a free kick by Barcelona star Alexis Sanchez. The ball went straight to Arranguiz who struck it into the net.
Casilllas seemed shell-shocked as he walked off at half-time. Defender Sergio Ramos and other Spanish players also shook their heads in disbelief.
Spain’s pitiful state seemed to be epitomized by misses in the second half. Diego Costa had a shot deflected wide and in the 53rd minute Sergio Busquets’s was clear in front of goal but a seemingly simple tap in went wide.
Chile’s goalkeeper Claudio Bravo pulled off a brilliant reflex save to stop an Andres Iniesta shot in the 84th minute.
The historic Maracana stadium erupted into a riot of red and blue as Chilean supporters started noisy celebrations. Thousands crossed the Andes in special convoys to watch Chile’s games.
Chile play Netherlands to decide top place in Group B on June 23. Spain play their final game against Australia on the same day.