Crestfallen Michael Phelps says his narrow defeat in the 100 metres butterfly final at the U.S. National Championships in California on Friday will serve as motivation to not get beaten again.

Tom Shields edged out the 18-times Olympic gold medalist by the smallest of margins, 0.01 seconds, to win in 51.29 seconds at the meet in Irvine.

Despite the defeat, Phelps did enough to earn a berth on the American team for the Pan Pacific Championships in Queensland, Australia later this month in perhaps his strongest event.

However, the 29-year-old was not happy to be beaten, especially after clocking the fastest time in the world this year (51.17) in the morning heats, a performance he could not replicate the final.

Phelps, who has won the event at the past three Olympics, was well behind after 50 metres and a mediocre turn left him with a big deficit to make up. It was only in the final few metres that Phelps challenged Shields, who just held on.

"I'm somebody who can't stand to lose," Phelps told reporters as he continues his comeback to competitive swimming after retiring from the sport following the 2012 London Olympics.

"I don't care if it's by a hundredth or by five seconds. This will definitely motivate me.

"I just felt out of it, not my normal self at finals. Normally, I'm very relaxed and very ready. It's probably just because I'm not used to being in this kind of shape or this kind of feeling going into a meet.

"Normally, I can look back and say I've done all the training, I've done everything I needed to do to prepare myself.

"With having a year and a half off and maybe not really going as hard as I probably should have at some of the parts during the year, it shows."

Phelps, who came out of retirement in April, finished seventh in the 100m freestyle on Wednesday, and has two more events over the weekend.