Phelps, who became the first person to win eight gold medals in a single Olympics in Beijing four years ago, conserved his energy by slowing down dramatically during the fifth of six qualifying heats for the 400-meter individual medley.
He won the heat in the time of 4:13.33, but times in the final heat were so fast that Phelps suddenly found himself in danger of missing out on Saturday night's final.
His time turned out to be the eighth fastest, meaning he will swim in an outside lane during the finals.
Phelps will compete in seven events at these Games and needs only three medals to break the all-time record of 18 currently held by Ukranian gymnast Larysa Latynina -- a mark that has stood for 48 years.
American Ryan Lochte, who defeated Phelps in the individual medley at the U.S. Olympic swimming trials last month, qualified third for Saturday's finals. The fastest qualifying time of 4:10.01 was turned in by Japan's Kosuke Hagino.
In other qualifying early Saturday, Dana Vollmer of the United States set an Olympic record of 56.25 while grabbing a spot in the women's 100-meter butterfly semifinals.
Celebrity Couples of 2014 [PHOTOS]