Ferrer, who also beat Andy Roddick on Friday night, gave Spain an insurmountable 3-1 lead and a home semifinal against France _ a replay of the 2010 final _ in September.
Playing without world No. 2 Rafael Nadal, Spain had to overcome a rowdy pro-American crowd to earn its first Davis Cup victory in the U.S. and continue its quest for a third title in four years.
Defending champion Serbia had little trouble finishing off Sweden, winning both reverse singles Sunday to secure a 4-1 victory and a semifinal against Argentina, which beat Kazakhstan 5-0.
Janko Tipsarevic beat Michael Ryderstedt 6-2, 7-5, 6-3 to give Serbia an unassailable 3-1 lead at Halmstad, then Viktor Troicki made it 4-1 for Serbia when Robert Lindstedt retired in the third set of the last singles match.
The Serbians won the two opening singles matches but Swedish pair Simon Aspelin and Robert Lindstedt stunned top-ranked Novak Djokovic and Nenad Zimonjic in Saturday's doubles match.
Djokovic skipped the singles to rest his sore left knee, while Robin Soderling didn't play at all for Sweden, saying he needed time to rest.
"It feels really great," Tipsarevic said. "I know that Serbia was a huge favorite to win with Robin Soderling not here and Novak coming, but I'm happy to have helped my country once again get through to the semifinals." France completed a 4-1 victory over Germany by splitting Sunday's reverse singles. The French were already assured of a place in the semifinals after winning Saturday's doubles to take an unassailable 3-0 lead. With both reverse singles reduced to best-of-three sets, Philipp Petzschner earned Germany's only point by beating Michael Llodra 6-3, 6-4, before Jo-Wilfried Tsonga beat Philipp Kohlschreiber 7-6 (3), 7-6 (5) in the last match.