Spain's David Ferrer retired from his quarterfinal match here at the Abierto Mexicano Telcel with a leg injury, while second-seeded Scotsman Andy Murray came back from the brink to win in three sets.

Ferrer won the first set of Thursday's match against South Africa's Kevin Anderson by the score of 6-2, but he injured his leg in the fifth game of the second set and fell to his knees on the court in pain.

The world No. 4 and top seed called for the trainer and took a medical time-out after losing serve to go behind 3-2, and he subsequently opted to retire and avoid aggravating the injury when Anderson held serve in the ensuing game.

The injury snaps a string of final appearances for Ferrer dating back to 2010 at the Acapulco event, whose surface was changed from clay to hard this year. The 31-year-old won the 2010, 2011 and 2012 titles, but lost in last year's final to countryman and world No. 1 Rafael Nadal.

Next up for Anderson in Friday's first semifinal will be Ukraine's Alexandr Dolgopolov, who defeated big-serving Croat Ivo Karlovic 6-4, 7-6 (7-4).

Both of the other semifinalists had to rally from a set down Thursday night, with each spending more than two and a half hours on court to record their victories.

First, Murray came back from a set and a service break down to edge Frenchman Gilles Simon, who came up short in his bid to win his second match in 13 tries against the Scotsman.

Simon served for the match at 6-1, 5-3, but he squandered that opportunity with a poor service game. Poor net play then doomed his chances in the tiebreaker and Murray took control of the match in the third set to win 1-6, 7-6 (7-4), 6-2.

Murray said afterward that he needs to find a way to get off to better starts in his matches after falling behind early in all three of his contests in Acapulco.

In the late match, Bulgaria's Grigor Dimitrov also rallied from a dreadful start to defeat Latvia's Ernests Gulbis 4-6, 7-6 (7-2), 7-5.

After losing serve three times in the first set, Dimitrov settled down and eked out a close win in just under two hours and 40 minutes.

Murray and Dimitrov will square off in Friday's late semifinal.