Eighth seed Ferrer, a finalist in 2014, needed two hours to beat Georgian Basilashvili 6-2 3-6 6-3 and will next face Argentina's Federico Delbonis.
Jiri Vesely also had a three-set battle with Fernando Verdasco in prevailing 7-6 (9/7) 6-7 (0/7) 6-3, while Aljaz Bedene cruised past lucky loser Jose Hernandez-Fernandez 6-1 6-2.
Florian Mayer beat Andrey Kuznetsov 6-3 4-6 6-4 to set up a quarter-final meeting with sixth seed Diego Schwartzman, the Argentinian defeating Cedrik-Marcel Stebe 1-6 6-4 6-2.
Verdasco handed two-month doping ban after positive test
At the Swiss Open in Gstaad, top seed David Goffin fended off four match points to win a tense encounter with Moldovan Radu Albot 2-6 7-6 (9/7) 7-6 (9/7).
Goffin, who reached the Gstaad final in 2015, was down 3/6 in the third-set tie-break.
But he reeled off three consecutive points and eventually crossed the finishing line to set up a quarter-final showdown with Dutchman Robin Haase.
The sixth-seeded Haase, a runner-up in 2013 and 2016, did not face a break point in a 7-5 7-5 win over Brazil's Thiago Monteiro.
Switzerland's Henri Laaksonen, Spaniard Roberto Bautista Agut and fifth seed Paolo Lorenzi all booked their places in the second round.
Serena v Sharapova, Federer v Ferrer: Tennis’ most surprising head-to-head records
28/09/2022 AT 10:10
ATP Madrid
'He has something special' - Ferrer reveals moment he realised Alcaraz talent
30/04/2022 AT 10:08