By Steve Keating

TORONTO (Reuters) - Having ended his career once in London on what he considered a sour note, Michael Phelps enters the Rio de Janeiro Olympics pool for his second swansong determined to bow out on his own terms.

Inspired, motivated and sober, Phelps heads to Rio with the chance to add to his record total of 22 medals and to pen the happy ending he feels he denied himself four years earlier.

At the 2012 London Olympics, which he also declared would be his last, Phelps won four gold and six medals but walked away filled with the regret that he simply went through the motions rather than embracing the moment.

"Going into '12, I just didn't want to do it," the 31-year-old said at the U.S. Olympic swim trials in Nebraska last month.

"I tried to fake it. I wanted to get in and out as fast as I could and really wanted nothing to do with it.

"That haunted me for a while.

"I came back because I wanted to. I wanted to do this for me. I'm enjoying the moment and I'm embracing the moment and taking it one step at a time.

"Being able to fall in love with the sport again is something that I've always wanted to do again and I did it on my terms."

Like many athletes, when his career finished, Phelps appeared lost and unprepared.

He talked of becoming a professional golfer but eventually found himself testing the waters of a swimming comeback.

That return was interrupted by a second drunk driving arrest in 2014 and a stint in rehab, which laid the foundation for his transformation from party boy to family man.

He reconnected with his estranged father, who was in the stands at the U.S. swimming trials watching his son qualify for a fifth Olympic team, and in May his fiancée Nicole gave birth to their son Boomer.

TEAM CO-CAPTAIN

While Phelps has been a hero for a generation of American swimmers, he has now finally become something of a mentor and elder statesman of the U.S. team.

At each Olympics the U.S. swimming team picks a captain and until a July training camp in San Antonio, it had remained one of the very few honors not bestowed on Phelps.

Now, chosen as co-captain of the men's team for the first time, he is eager to assume the leadership mantle in Rio.

"This time around, I just want to be able to help some of the younger guys," said Phelps.

"Just being able to help them just kind of stay in their relaxed zone, not get worked up because it is the Olympics."

The growing maturity has not diminished the fierce competitiveness, however.

Having qualified for Rio in three events, the 100 and 200 meters butterfly and 200 individual medley, he will also be a candidate for the relays as he looks to add to his astonishing tally of 18 gold medals.

Phelps has made the 100 fly and 200 medley gold medals his personal property at the last three Olympics and he could join discus thrower Al Oerter (1956-68) and long jumper Carl Lewis (1984-1996) as the only athletes to win gold in the same individual event at four consecutive Games.

While still an undeniable force, Phelps no longer competes with the aura of invincibility that once surrounded him.

He conceded that his times at the U.S. trials would have to dramatically improve for Rio, but is confident his longtime coach Bob Bowman will have a plan to get him to the wall first.

"I do understand that I have to swim faster to have a chance to win the gold medal," said Phelps. "I've trusted that man since I was 11 years old, and it's not going to stop.

"I'm sure he's already come up with some kind of plan to figure out what we're going to do.

"I'm not going to put a limit on myself of what I can or can't do."

(Editing by Greg Stutchbury and Nick Mulvenney)