After a blistering start, Djokovic had to battle back from 3-0 down in the deciding set to book his place in the last 16 on Thursday against Feliciano Lopez or Gilles Simon.
Djokovic is without a coach in the Spanish capital after bringing to an end a 10-year relationship with Marian Vajda in an attempt to reverse his dramatic slump in form over the past year.
Almagro had taken just one set from four previous meetings with Djokovic, but willed on by a partisan home crowd, he held on to his serve despite more pressure from the Serb in the first game of the second set.
The Spaniard had to save two break points to hold for 4-3 and then took his chance to break with Djokovic serving to stay in the set.
However, a mixture of Almagro nerves and Djokovic upping his intensity saw the world number two react immediately to level at 3-3.
More Almagro errors flowed to give Djokovic another break for 6-5 and he served out for the match.
Djokovic could meet Rafael Nadal in the semi-finals.
However, the 14-time Grand Slam champion has a difficult route to that potential matchup as he faces Fabio Fognini later on Wednesday and potentially Nick Kyrgios in the third round.
Kyrgios and Nadal have only met twice with the Australian making his breakthrough with a four-set win over the 14-time Grand Slam champion at Wimbledon in 2014.
Nadal, though, edged their only previous meeting on clay at the Rome Masters last year.
Fifth seed Milos Raonic is also into the last 16 as he got the better of a battle between two big servers 6-4, 6-4 over Gilles Muller.
Raonic will face Belgium's David Goffin next.
Kei Nishikori recovered from a dreadful start to beat Argentine Diego Schwartzman 1-6, 6-0, 6-4.
Ferrer progressed as Jo-Wilfried Tsonga withdrew with a shoulder injury.
In the WTA Madrid Open, Svetlana Kuznetsova remained one of only three of the top 10 seeds left in the draw with a 6-4, 7-5 win over Wang Qiang to reach the quarter-finals.
Kuznetsova will face the winner of an intriguing clash between top seed Angelique Kerber and Eugenie Bouchard, who dumped out Maria Sharapova in thrilling fashion on Monday.
Disclaimer: No Business Standard Journalist was involved in creation of this content
You’ve reached your limit of {{free_limit}} free articles this month.
Subscribe now for unlimited access.
Already subscribed? Log in
Subscribe to read the full story →
Smart Quarterly
₹900
3 Months
₹300/Month
Smart Essential
₹2,700
1 Year
₹225/Month
Super Saver
₹3,900
2 Years
₹162/Month
Renews automatically, cancel anytime
Here’s what’s included in our digital subscription plans
Exclusive premium stories online
Over 30 premium stories daily, handpicked by our editors


Complimentary Access to The New York Times
News, Games, Cooking, Audio, Wirecutter & The Athletic
Business Standard Epaper
Digital replica of our daily newspaper — with options to read, save, and share


Curated Newsletters
Insights on markets, finance, politics, tech, and more delivered to your inbox
Market Analysis & Investment Insights
In-depth market analysis & insights with access to The Smart Investor


Archives
Repository of articles and publications dating back to 1997
Ad-free Reading
Uninterrupted reading experience with no advertisements


Seamless Access Across All Devices
Access Business Standard across devices — mobile, tablet, or PC, via web or app
