Ferrer, the fourth seed, had been on the brink of defeat in the third and fourth sets before progressing 4-6 4-6 7-5 7-6 (7-4) 6-2 after three hours 44 minutes.
Almagro, ranked 10th in Melbourne, must have thought he was on course for his first grand slam semi-final appearance as he raced through the first two sets and then led 5-3 in the third.
Ferrer, though, has never lost to his compatriot and rattled off four games on the bounce to keep alive his hopes.
An extraordinary fourth set saw both players struggle to retain their own serve - with eight breaks in total. Crucially for Ferrer, he was able to level the match when 5-4 and 6-5 down before going on to clinch the tiebreak.
The pressure and exertions were beginning to take their toll on Almagro, who was forced called for the trainer between sets.
And Ferrer took full advantage as he broke Almagro in the fifth and seventh games before serving out for the match.