The Russian, who is currently ranked 75th in the ATP rankings, defeated Djokovic, who won this year's Australian Open, 6-4, 7-6 (7-3), 6-2 in the center court match that lasted two hours and one minute.
"I just had to do what I had to do: serve well and try to stay with him. I could read his serve. I could return. I could stay with him from the baseline," the ATP website quoted Safin as saying in a post match interview.
Djokovic, who reached Wimbledon's semifinals last year but retired in the game against Rafael Nadal due to a blister, said he simply had a bad day and he underestimated Safin's abilities.
"I didn't do anything that I was supposed to do. He was very solid in all segments of the game. He was serving well, and like that, putting a lot of pressure on me," the 21-year-old Serbian said.
In the next round unseeded Safin will play against Italy's Andreas Seppi (29).