The Romanian, who lost the 2010 final to Stanislas Wawrinka, secured a 7-6 (7-3) 6-3 triumph on the clay surface and will now face number one seed and last year's runner-up Kevin Anderson in the next round.
Hanescu got off to a nightmare start against the Moroccan wild card, losing both of his opening service games to fall 3-0 behind, before responding strongly to take the set to a tie-break in which he was always ahead.
Khaddari seized the initiative in the second set, too, leading 3-1 before Hanescu broke three times to reel off five straight games and seal his place in the next round.
Sixth seed Federico Delbonis also progressed in straight sets, seeing off French qualifier Gilles Simon 6-4 6-4.
Delbonis broke his opponent in the very first game before holding his nerve to secure the first set.
The second was a similarly tight affair that went largely with serve, the Argentinian securing the crucial break in the ninth game to book a clash with Filip Peliwo, who defeated Italy's Filippo Volandri 7-6 (8-6) 6-3 to ensure his progress.
The Canadian recovered from being broken in the very first game to break back in the eighth and, after wasting two set points in game 10, got the better of his opponent in the tie-break to edge in front.
The second set was locked at 3-3 before Peliwo reeled off three successive games, breaking Volandri twice, to book a last-16 spot.
Joining him there is Albert Ramos, runner-up in 2012, who won in three sets against Lamine Ouahab, 6-3 2-6 6-1.
The Spaniard got off to a flying start, racing into a 4-0 lead before comfortably serving out to take the first, but Ouahab hit back in style in the second, breaking Ramos three times to level the match.
Ramos returned the favour in the decider, winning four successive games to close out the match and set up a meeting with fourth seed and compatriot Marcel Granollers.
Elsewhere, there was further joy for Spain as Roberto Carballes Baena defeated Belgium's David Goffin 6-2 7-5.