Stepanek, the world number 37, beat 11th-ranked Almagro 6-4, 7-6 (7/0), 3-6, 6-3 in three hours and 52 minutes in a clash of the teams' number-two players on the hardcourt of Prague's O2 Arena.
The Czech Republic lifted their first Davis Cup since gaining independence following a 1993 split with Slovakia. The former Czechoslovakia won the trophy in 1980.
The victory has also handed the Czechs a rare team double after their women lifted the Fed Cup here two weeks ago -- a feat last achieved by the United States in 1990.
"It's amazing, we've written history here in our country," a jubilant Stepanek said after the game.
"I cannot describe what I'm feeling right now," added the 33-year-old.
"There are no words to say. Undescribable. This is the best thing that can be," said Tomas Berdych, his teammate.
In Sunday's key rubber, a wild home crowd of more than 14,000 fans was all that Stepanek needed to shake off the fatigue from Friday's singles and Saturday's doubles.
His game against a rested Almagro went with serve until Stepanek capitalised on a single set point to break the Spaniard for a 6-4 win in the first set.
"I came on the court with a mindset that I have to stay calm, hungry, motivated, concentrated, and always know what I'm doing. And that's what I did," Stepanek said.
The crowd got even louder as Stepanek, combining patience with aggressivity, pulled off a series of winning volleys as he came back from 4-2 down in the second set.
He failed to convert four set points but then thrashed Almagro 7-0 in the tiebreak.
"I played very aggressive today, I didn't want to leave anything behind, I wanted to be the one who is active, who is controlling the game," Stepanek said.
Almagro fought back and held on to his serve to take the third set.
But Stepanek, red hot and propelled by the crowd, refused to bow and took the fourth and decisive set after breaking Almagro's serve once again.
In Sunday's first match, Spain's David Ferrer beat Berdych in straight sets.
Ferrer, the world number five, needed just two hours and 25 minutes to see off sixth-ranked Berdych 6-2, 6-3, 7-5.
The 27-year-old Berdych got off to a slow start, losing his opening service game in the first set and then another to let Ferrer, 30, move ahead without too much trouble.
"I played very focused, very aggressive, I started really good and maybe that was the key," Ferrer said, praising his first serve and forehand.
Ferrer broke Berdych's serve early in the second set for a 3-0 lead that prompted Berdych to take a bathroom break.
But even that did not help - Berdych was flat and allowed Ferrer to gain the upper hand in long exchanges and finally take the second and third sets too.
"It's very difficult to beat Tomas in three sets but I played one of the best matches of my career in Davis Cup," said Ferrer.
Berdych said he was upset he had failed to decide the tie.
"In Davis Cup this year, I have lost only one rubber and it was the last one," he said.
"Ferrer played an excellent game and I was always way behind him," Berdych added.
On Friday, Ferrer beat Stepanek 6-3, 6-4, 6-4 and Berdych then put the Czechs level after beating Almagro 6-3, 3-6, 6-3, 6-7 (5/7), 6-3.
In Saturday's doubles rubber, Berdych and Stepanek beat Marcel Granollers and Marc Lopez 3-6, 7-5, 7-5, 6-3 for their 12th victory in Davis Cup doubles against a single loss.
Spain, who had won the Davis Cup three times in the past five years, were missing world number four Rafael Nadal, who is recovering from a knee injury.