The current world number two tennis player, who was born in Basel, received the title from the medical faculty, which praised him for his role in increasing the international reputation of Basel and Switzerland.
He was also a role-model athlete who encouraged people worldwide to be more physically active and contributed to the promotion of a healthy lifestyle, the university said.
In a press release it also highlighted the 36-year-old sportsman's engagement for children in Africa through his charitable foundation.
Federer, who was not able to take part in the ceremony in person, expressed his appreciation, saying that the honorary doctorate made him as happy as any Grand Slam title.
His award was one of seven honorary doctorates given to outstanding members of society at the university's Dies Academicus on Friday.
Other recipients included Thomas Jordan, the president of the Swiss National Bank, and the musician Andrew Bond who writes and sings songs for children.