Stepanek, who jumped the net and waved his arms in triumph to the 14,580 packed into the arena, was hugged by team-mates before going to his wife with tears rolling down his cheeks.
The result meant the Czech Republic had claimed the Davis Cup for the first time as an independent nation 32 years after Czechoslovakia won the trophy with a team led by Ivan Lendl.
It also made the Czech Republic the first country to win the Davis Cup and Fed Cup team trophies for men and women respectively and the mixed Hopman Cup event in one year.
"I was dreaming about it my whole life and now we're standing here as Davis Cup champions, it's amazing," said Stepanek after clinching the 100th Davis Cup final.
His triumph delighted a home crowd that had earlier been silenced when Spain's David Ferrer cruised to a 6-2 6-3 7-5 win over Tomas Berdych to level the final at 2-2 after the Czechs won a bruising four-set doubles rubber on Saturday.
World number five Ferrer's victory over sixth-ranked Berdych put Spain, without injured former world number one Rafael Nadal, back in the hunt for a fourth Davis Cup crown in five years.
But 33-year-old Stepanek, ranked 37th in the world, used all his guile and experience to unnerve the 11th-ranked Almagro, who was appearing in his first final, and took the first set.
Stepanek, who became the first man aged 30 or above to win a decisive fifth rubber in 100 years, then forced Almagro into some costly errors in the second set tiebreak which he won 7-0.
The beginning of the third set was tight but Almagro served well and managed to win it before Stepanek clinched the fourth to send the Czech supporters into raptures inside the O2 arena.
"I can't describe what I'm feeling right now," said an emotional Stepanek whose victory helped avenge a 5-0 drubbing by Spain in the 2009 showpiece on the clay courts of Barcelona - the only other time the Czech Republic had reached the final.
"I came on the court with the mindset that I had to stay calm, hungry, motivated and concentrate... I was playing very aggressively today. I wanted to be the one who was active, who was controlling the game and it paid off."
The Czechs became the first country in 22 years to win the Davis Cup and Fed Cup in the same year but were pushed all the way by a Spanish team missing the talismanic Nadal.
"These are very tough moments," Almagro told Spanish broadcaster TVE after the defeat. "But we can't be down on ourselves in any way as we fought to the last moment.
"We are runners-up in the Davis Cup, not what we wanted as we came here to win the title but we are leaving with our heads held high knowing that we did a good job."