GWANGJU, South Korea — In her first individual race since illness knocked her out of two events this week at the world swimming championships, Katie Ledecky posted the second-fastest qualifying time in the 800-meter freestyle on Friday, behind her American teammate Leah Smith.

Ledecky, a two-time Olympic champion in the event who owns the 22 best times in its history, closed fast over the final 150 meters and nearly caught Smith, who was in an adjoining lane. Ledecky touched the wall in 8 minutes 17.42 seconds, almost 13 seconds slower than her world record and a blink behind Smith’s 8:17.23.

Ledecky appeared sapped by the effort, proceeding straight to the warm-down pool without stopping to talk to reporters.

The final on Saturday will cap a turbulent week for Ledecky, one of the sport’s most dominant performers, and will give her a chance to salvage one gold medal from a meet where she was favored to win at least three.