The two 32-year-olds could barely be separated throughout, each earning plenty of chances and breaking the other three times during the course of the match, but it was the Spaniard who held his nerve better in the final set as he won 7-6(2) 4-6 6-3 to set up a clash against world number four Tomas Berdych.
There were no such problems for Germany's Philipp Kohlschreiber as he won in straight sets against Chinese wildcard Mao-Xin Gong, who is ranked 695 places below him in the world.
An upset briefly seemed possible, however, with Gong delighting the home crowd by going toe-to-toe with the world number 23 throughout the first set before just failing to push it to a tie-break as he lost his serve at last in the 12th game of the set.
Kohlschreiber went on to win 7-5 6-2 and will face world number six Juan Martin del Potro in the next round.
The French duo of ninth seed Richard Gasquet and 13th seed Gilles Simon were the highest ranked players to get knocked out, with Gasquet losing 6-3 6-4 to Canda's Vasek Pospisil and Simon losing to another Frenchman, Benoit Paire, 6-4 6-3.
Latest results from the Shanghai Masters Men's Singles Round 1 matches on Tuesday
Vasek Pospisil (Canada) beat 9-Richard Gasquet (France) 6-3 6-4
10-Milos Raonic (Canada) beat Michal Przysiezny (Poland)
12-Kei Nishikori (Japan) beat Grigor Dimitrov (Bulgaria) 6-3 6-4
Benoit Paire (France) beat 13-Gilles Simon (France) 6-4 6-3
15-Nicolas Almagro (Spain) beat Go Soeda (Japan) 7-6(5) 6-2
16-Tommy Robredo (Spain) beat Albert Montanes (Spain) 6-4 6-1
Jeremy Chardy (France) beat Bernard Tomic (Australia) 7-5 6-2
Alexandr Dolgopolov (Ukraine) beat Michael Russell (U.S.) 6-1 6-3
Daniel Brands (Germany) beat Alejandro Falla (Colombia) 7-6(3) 7-5
Fabio Fognini (Italy) beat Paolo Lorenzi (Italy) 4-6 7-6(5) 6-4
Kevin Anderson (South Africa) beat Victor Hanescu (Romania) 4-6 7-6(5) 7-6(4)
Feliciano Lopez (Spain) beat Jarkko Nieminen (Finland) 7-6(2) 4-6 6-3
Philipp Kohlschreiber (Germany) beat Gong Maoxin (China) 7-5 6-2
Andreas Seppi (Italy) beat Lleyton Hewitt (Australia) 6-4 6-2
Fernando Verdasco (Spain) beat Zhang Ze (China) 7-5 6-2
Jurgen Melzer (Austria) beat Ivan Dodig (Croatia) 4-6 6-3 6-4