Williams, 37, had shown signs of fatigue during the first set and after it was completed she called for a trainer and following a lengthy conversation returned to the court.
She retired after losing the first game.
Williams had taken a 3-0 lead in the first set before losing the next seven games.
Williams, who has won 23 Grand Slam singles titles, gave birth to a daughter in 2017 and returned to play last year.
She is currently ranked 10th in the world.