The Serb came from behind before edging a tight third set to triumph 6-7 6-3 6-4.
Almagro, who replaced the sick Rafael Nadal, who has since pulled out of the Australian Open following a virus, took a surprise lead as he won the opening set on a tie-break.
His opponent responded quickly to claim an early break in the second set and although Almagro fought hard, the Serb underlined his resilience by keeping daylight between the two.
The pair were 3-3 in the deciding set and could not be separated but Djokovic broke in the final game of the match to clinch victory.
Earlier in the afternoon, David Ferrer beat Janko Tipsarevic as he won the third-place play-off 7-6 (7-4) 6-2.