The world number one, who had seen off Pablo Andujar Alba just 24 hours earlier, appeared jaded but came good on the big points to claim a 6-3 6-4 win.
The Serb was the first to break serve, doing so in the fourth game, but he was immediately pegged back by superior hitting from his Spanish opponent.
Almagro then wasted his good work with an error-filled game, as Djokovic made it three consecutive games against serve and then shakily served out for the set.
Djokovic struggled to make an impact against the Almagro serve early in the second set and twice had to call on big first serves to retain his own.
After failing to convert four break points in a 12-minute game seven, Djokovic finally gained the crucial second-set break in game nine, when his backhand, which had failed him consistently throughout the match, finally came good and delivered a tidy cross-court volley.