Reigning Olympic champion Michael Phelps reached the final of the 400m individual medley at the London Games by the skin of his teeth, nabbing the eighth and last spot.
Phelps, who has 16 career medals including 14 gold, is swimming seven events and needs just three medals to surpass Soviet gymnast Larisa Latynina's Olympic career record of 18.
Phelps won his heat in 4min 13.33sec, but the leisurely pace of that race saw second-place finisher Laszlo Cseh of Hungary — a medallist at the last two Games, shut out of the final.
Japan's Kosuke Hagino led the way into the final with a time of 4:10.01, followed by South African Chad le Clos and American Ryan Lochte, who was runner-up to le Clos in the final heat.
Phelps and arch-rival Lochte are on a collision course in the medley.
Phelps' haul of eight gold medals from the Beijing Olympics four years ago included the 400m medley title, but he was beaten by Lochte, the reigning world champion, at the US trials.
Phelps is aiming to become the first male swimmer to win a gold medal in the same individual event in three successive Olympic Games and will not surrender his crown without a fight.