Ferrer's exit leaves Andy Murray as the big favorite to win the Mexican Open 500. The Scot overcame a poor start to beat Frenchmen Gilles Simon 1-6, 7-6 (4), 6-2.
"It's tough to win matches when you get down like that, I've been struggling with my service in the first two matches", said Murray, who will play against the winner of the match between Latvia's Ernests Gulbis and Bulgarian Grigor Dimitrov.
Murray has beaten Simon 12 straight times.
Third-ranked Ferrer was leading 6-4, 2-2 when he suffered an inner thigh strain in his left leg. After seeking treatment in the locker room, the Spaniard returned to the court but lost the next two points before retiring.
Ferrer said he will have scans on Friday and then assess his recovery.
"I'm very sad because I was playing great", Ferrer said. "I still do not know the extent of the injury.
"I'll have to wait and see before taking a determination. The day was going so well for me and then this happened".
Anderson will next play Ukraine's Alexandr Dolgopolov, who defeated Ivo Karlovic of Croatia, 6-4, 7-6 (4). Anderson, who last week lost the Delray Beach final, will be playing in his first semifinals of an Open 500.
"It's unfortunate to win a match like this, but hopefully he gets better", Anderson said after the match. "I talked to him and he said that it happened when he was trying to go for a ball and felt his leg tweak a little bit".
On the women's side of the tournament, top-seeded Dominika Cibulkova of Slovakia defeated New Zealand's Marina Erakovic 6-4, 7-5 to set up semifinal against China's Shuai Zhang.
Zhang, the eighth seed, ousted Ajla Tomljanovic of Croatia 6-1, 5-7, 6-2.
Canada's Eugenie Bouchard suffered a surprise 3-6, 6-4, 6-1 loss to France's Caroline Garcia.
Garcia, 89th in the WTA rankings, will play in the semifinals against American Christina McHale, who defeated third-seeded Kai Kanepi from Estonia 6-1, 2-6, 6-4.