The Czech Republic won the Davis Cup for the first time as an independent nation Sunday, beating Spain 3-2 in the final after Radek Stepanek upset Nicolas Almagro in the last reverse singles.

The 37th-ranked Stepanek beat his 11th-ranked opponent 6-4, 7-6 (0), 3-6, 6-3, converting his second match point to send the 14,500 fans at the O2 Arena into wild celebration as they blew trumpets and beat their drums.

Stepanek dropped to the court in disbelief before teammates Tomas Berdych, Lukas Rosol, Ivo Minar and captain Jaroslav Navratil jumped on him.

"Davis Cup champions! That's amazing," Stepanek said. "We made history today and I hope the entire nation will be celebrating with us."

The victory means the Czechs completed a rare double just two weeks after the women secured the Fed Cup title in the same arena. No country has won both competitions in the same year since the United States in 1990.

"There's nothing more to achieve," Berdych said. "I have nothing to say more. This is a moment we never forget."

The Czechs' only previous victory came in 1980 as Czechoslovakia, which split in 1993, with a team led by Ivan Lendl.

"They've been our inspiration, our idols. They're the legends and now we're joining them," Stepanek said.

It was sweet revenge for the Czechs after they were swept 5-0 by Spain in the 2009 final at Barcelona, with Stepanek losing to David Ferrer in five sets.

"We're sad at this moment," Ferrer said. "I'm very proud of our team. We were fighting to win here in Prague."

This weekend, Stepanek had three tough matches. He lost to Ferrer in straight sets in the opening singles Friday, but teamed up with Berdych to win the doubles Saturday.

"I was playing very aggressive today; I wanted be the one who is active, who is controlling the game," Stepanek said. "It paid off, even though I lost the third set. I had no doubt I was on the way."

Earlier Sunday, Ferrer kept alive Spain's hopes of winning a fourth Davis Cup title in five years by beating Berdych 6-2, 6-3, 7-5 in the first reverse singles match to tie the final at 2-2.

Ferrer is wrapping up the best season of his career with a tour-best seven tournament titles. He converted his first match point for his 76th win of the year when Berdych's forehand hit the net, bringing cheers from the boisterous section of Spanish fans.

"I was always a few steps behind him," said Berdych, who had been undefeated in the Davis Cup this year. "He was just playing too good today."

The Czechs beat Italy, Serbia and Argentina en route to the final. Spain, without the injured Rafael Nadal, had been looking for its sixth title.