Rafael Nadal helped hosts Spain see off Argentina in a deciding doubles contest, setting up a semi-final against Great Britain.
Serbia had hoped to mark Janko Tipsarevic's farewell by winning the Davis Cup, but Russia ruined those plans in Madrid on Friday.
Kyle Edmund will once again play in the singles for Great Britain, meaning Andy Murray will be a spectator for their quarter-final tie.
Alex de Minaur's comeback win was not enough to inspire Australia, as Canada became the first team to book a semi-final berth in Madrid.
Spain will be without Roberto Bautista Agut for the rest of their Davis Cup campaign after the world number nine's father died.
Andy Murray may not feature for Great Britain in Friday's Davis Cup quarter-final tie with Germany, according to captain Leon Smith.
Thanks to Novak Djokovic and Filip Krajinovic, Serbia reached the Davis Cup quarter-finals alongside Great Britain and Germany.
Croatia's hopes of retaining the Davis Cup are over after they were beaten by hosts Spain in Madrid.