Updated

Ryan Lochte bested Michael Phelps and captured the 400-meter individual medley on Monday night at the USA Olympic swimming trials.

Lochte posted a time of 4:07.06 seconds, while Phelps finished in 4:07.89 to become the first swimmer in United States history to qualify for four Olympics.

The top two finishers in each race qualify for the Olympics

Lochte has had Phelps' number lately. The 27-year-old won five gold medals and both of his head-to-head races against Phelps during last year's world championships.

It was the first time that Phelps tasted defeat in a final at the U.S. trials since Ian Crocker took him down in the 100 butterfly on July 13, 2004.

Phelps is the two-time defending Olympic champion in this event.

In addition to Lochte's triumph, Peter Vanderkaay is headed to his third straight Olympics by winning the 400 free, while 19-year-old Elizabeth Beisel will make her second consecutive Olympic trip after prevailing in the 400 individual medley.

Vanderkaay registered a time of 3:47.67, good enough to stave off runner-up Conor Dwyer, who finished the race in 3:47.83.

Beisel had a dominating performance, posting a time of 4:31.74, which was almost three seconds better than Caitlin Leverenz, who clocked in at 4:34;48.

Dana Vollmer set an American record in the semifinals of the 100 butterfly, finishing the race in 56.42 seconds and surpassing the mark of 56.47 she set a year ago.