The world number two, who has never lost to Ferrer, survived an early scare on his serve before breaking his opponent to take a 2-0 lead.
Ferrer refused to give up the set easily though, and pulled level with a break of serve of his own. However, the Spaniard made a number of mistakes towards the end of the opener and gifted Federer three set points, which the Swiss ace gratefully accepted.
Ferrer's determination meant Federer was not able to wrap up the match quickly and the second set had to be decided by a tie-break.
Federer's quality shone through at the end of the decider as he won the tie-breaker 7-5 to ensure his progress with one match to be played in the round robin stage, against Juan Martin del Potro.