Rafael Nadal came through a severe test against Novak Djokovic to guarantee himself at least a silver medal in the Olympics after a 6-4 , 1-6 , 6-4 win that ended in the small hours of the morning in Beijing .