The 44th-ranked Almagro dogged the No. 1, making Murray work overtime to secure a semifinal berth.
Almagro finally surrendered after 2 hours, 9 minutes, when he shipped a backhand crosscourt wide on a second match point for Murray in the final game.
Murray trailed 3-1 in the first set, and squandered a 2-1 advantage with a service break in the second set.
The difference for Murray was in the second serve points won percentage in which he was at 61 and Almagro was at only 47.
"It was a very tough match," Murray said. "Nico was playing very aggressive and going for his shots. It was hard conditions tonight, very windy, so tough to get into much of a rhythm."
Interestingly, Murray reached the quarterfinals with a nearly similar 7-6 (6), 7-5 result over Gerald Melzer on Wednesday.
"The first week of the year there's a little bit of nerves," Murray said. "You want to make sure you get some matches with Australia (Australian Open) just around the corner."
Murray, a two-time Qatar Open winner, is on a 27-match winning streak.
In the semifinals, he will play third-seeded Tomas Berdych, who ousted fifth-seeded Jo-Wilfried Tsonga 7-5, 6-3.
"It's a soft term saying windy for what it's been today," Djokovic said. "It's quite challenging I must say, mentally mostly, to really be able to go through these kind of conditions without losing the focus and the determination on the court.
"There is not much you can do. The force of nature is like that. You have to accept and try to embrace it, really be one with the wind, otherwise it's not going to be a good day for you."
Djokovic holds a 13-1 career record over the 38-year-old Stepanek and has won their last 12 meetings.
Djokovic took a 4-2 lead in the first set before Stepanek broke Djokovic's serve when the second seed netted a backhand on a third break point.
Djokovic won the next two games, winning the set on an overhead smash to an open court.
In the second set, Djokovic established a 3-1 lead and held on.
Djokovic will play Spaniard Fernando Verdasco in the semifinals. Verdasco beat sixth-seeded Ivo Karlovic of Croatia 6-2, 7-5.