The seventh-seeded Scot returned to singles action having taken a break in an inconsistent year that has seen him fall down the rankings.
Earlier, Rafa Nadal launched the defence of his Madrid Open title by breezing past Juan Monaco 6-1 6-0 to rediscover his touch on his favoured clay after surprise exits in his last two tournaments.
The world No 1 went out in the quarter-finals at both Monte Carlo and Barcelona last month, but his extra quality shone through in his second-round match against the 56th-ranked Monaco.
Murray made a storming start against Almagro, with two breaks of serve on his way to winning the first set.
He outplayed the Spaniard with his power and speed around the court but the second set was very different, as Almagro found his range and Murray's head went down.
Almagro, who knocked Nadal out of the Barcelona Open, looked in charge but it was a much tighter final set, in which Murray rediscovered his consistency to win.
"It was a tough match, he was going for bombs with every shot and huge serves. He was ripping the ball from the back of the court," Murray told reporters.
Admitting that he does not find it easy on clay, he added: "I have been struggling on it in the last few years, physically. It's a question of keeping on top of the recovery. The aim is to stay fit for the French Open and the next few weeks are very important."
Nadal, seeking a fourth Madrid Open title, established a 2-0 lead and never looked back.
Although he was not at his best, the power and accuracy of his shots were too much for the Argentine, with the match ending in 68 minutes.
The Spaniard is gearing up for the French Open at Roland Garros, where he has won a record eight titles.
In the last nine seasons, he has won at least two European claycourt titles ahead of the French grand slam, but he is yet to win in his home continent this year, with his only 2014 victory on the red dust coming in Rio de Janeiro in February.
"All the wins are useful to improve your confidence. At the start it was more difficult, I moved nervously. Then after that I played better than I have been doing," Nadal told reporters.
He now faces a quarter-final against Jarkko Nieminen, who beat Igor Sijsling 6-3 6-2.
"We know each other very well, we've played a lot of times. He is a fighter and left-handed as well so it will be a tough game," Nadal said of the 57th-ranked Finn.
Second round results
7-Andy Murray (Britain) beat Nicolas Almagro (Spain) 6-1 1-6 6-4
Marin Cilic (Croatia) beat Paul-Henri Mathieu (France) 6-4 1-6 6-2
Santiago Giraldo (Colombia) beat 11-Jo-Wilfried Tsonga (France) 6-4 6-3
Feliciano Lopez (Spain) beat 15-Mikhail Youzhny (Russia) 3-6 6-3 6-4
12-Grigor Dimitrov (Bulgaria) beat Marius Copil (Romania) 4-6 6-3 7-6(7)
9-John Isner (U.S.) beat Marinko Matosevic (Australia) 7-6(9) 6-7(5) 7-5
1-Rafa Nadal (Spain) beat Juan Monaco (Argentina) 6-1 6-0
Jarkko Nieminen (Finland) beat Igor Sijsling (Netherlands) 6-3 6-2
Ernests Gulbis (Latvia) beat Alexandr Dolgopolov (Ukraine) 6-3 6-4
Lukasz Kubot (Poland) beat Gilles Simon (France) 7-5 2-6 6-4
6-Tomas Berdych (Czech Republic) beat Kevin Anderson (South Africa) 6-1 6-4
- Sports & Recreation
- Juan Monaco
- Rafa Nadal