By Alan Baldwin

RIO DE JANEIRO (Reuters) - Ryan Lochte of the United States qualified fastest on Wednesday for the semi-finals of the Olympic 200 metres individual medley, two places ahead of his career-long team mate and rival Michael Phelps.

Lochte clocked one minute 57.38 seconds in the afternoon heats, with Philip Heintz of Germany second in 1:57.59 and Phelps third in 1:58.41.

In the same event at London in 2012, Phelps took the gold medal and Lochte won silver.

Phelps was swimming the morning after winning the 20th and 21st gold medals of his career in the 200m butterfly and the 4x200m freestyle relay, in which Lochte won his sixth gold.

"Definitely fatigued a little bit," said Phelps, who told reporters he had got about five hours sleep. "My body hurt a little bit but with some good rest this afternoon I think I'll be fine."

The 31-year-old added: "I've been able to put my body through things like this over the years and hopefully I can keep it rolling one last time.

"Leaving everything in the pool one last time is what I'm going to do, and if that's good enough to win, we'll see."

Lochte, 32, said: "This week, we're just getting started. USA, we always show up when the time's right. Especially last night and the night before, just seeing USA just rocking and we're going to keep that really for the rest of the week."

There was plenty for Brazilian fans to celebrate, with Henrique Rodrigues qualifying fourth and Thiago Pereira fifth.

Pereira, swimming in the lane next to Phelps in their heat, excited the crowd by leading him over the butterfly, backstroke and breaststroke legs before the American pulled away with his long easy stroke in the freestyle.

Kosuke Hagino of Japan, who won the 400m individual medley on Saturday, was sixth out of 16 to make it through to the semis.

(Additional reporting and writing by Mark Trevelyan; Editing by Toby Davis)