VALENCIA, Spain (AP) — With Rafael Nadal nervously cheering courtside after winning his match earlier Sunday, David Ferrer sealed Spain's 3-2 comeback win over Germany in the Davis Cup quarterfinals with a thrilling five-set victory against Philipp Kohlschreiber.

Ferrer needed nearly five hours to defeat Kohlschreiber 7-6 (1), 3-6, 7-6 (4), 4-6, 7-5 at the packed bull ring in Valencia, guaranteeing Spain's return to the semifinals for the first time since 2012. Spain will now face France, which defeated Italy 3-1.

Nadal and the local crowd erupted in celebration when the 33rd-ranked Ferrer successfully served for the match after breaking Kohlschreiber's serve in the previous game. Kohlschreiber, No. 34 in the world, ended with 114 unforced errors.

Spain extended its winning streak at home to 27 ties. Italy holds the Davis Cup record with a 29-tie unbeaten run at home from 1949-64. Spain hasn't lost a tie as host since the first round in 1999 against Brazil.

Top-ranked Nadal cruised to a 6-1, 6-4, 6-4 win over fourth-ranked Alexander Zverev in the first match Sunday to keep Spain alive after entering the day trailing 2-1.

Nadal was dominant against the 20-year-old German to earn his 24th straight win since 2005, the most in Davis Cup history combining singles and doubles.

Nadal had easily defeated Kohlschreiber on Friday in what was his first match since the Australian Open in January because of a right hip injury. Zverev had given Germany a 1-0 lead by defeating Ferrer in three sets. Germany also won the doubles match on Saturday.