Spain's red clay in three hours.
Almagro then triumphed in a four-hour slog against John Isner, winning 6-4, 4-6, 6-4, 3-6, 7-5.
If Spain's doubles team of Marcel Granollers and Marc Lopez beat the American twins Bob and Mike Bryan on Saturday, the five-time champions will be through to the final to defend their title.
Ferrer lost his first set to Querrey but tamed the gangly American's blistering forehand with deft returns to the delight of the rowdy crowd.
"It was a hard match, difficult at every moment," said Ferrer, 30, currently Spanish number one in the absence of injured Rafael Nadal.
Ferrer had arrived in Gijon straight from the US Open where he lost to Novak Djokovic in the semi-finals.
One of the world's finest clay-court players, along with world number 12 Almagro, Ferrer stamped out Querrey's resistance in their fiercely-fought fourth set, defending several break points in a series of dazzling rallies.
Bryans’ win set up tense final day
Bob and Mike Bryan beat Marcel Granollers and Marc Lopez 6-3, 3-6, 7-5, 7-5 on Saturday as the United States stayed alive in their Davis Cup semi-final against defending champions Spain.
Trailing 2-0 overnight on the clay courts of Gijon, the Olympic and US Open champions secured a crucial point which will mean the tie will be decided on Sunday with a place in November's final at stake.
Saturday's rubber lasted three hours 38 minutes as the Bryans took their Davis Cup record to 20-2.
"They're pretty good in the clutch and they get us to Sunday when we're in this position all the time. We've got a chance," said US captain Jim Courier.
Five-time champions Spain are defending a run of 23 consecutive home victories in the tournament, a streak stretching back to 1999. They had edged closer to a sixth final in 10 years on Friday.