MESA, Ariz.— There was a time, before the 2012 Olympics, when swimming became a grim exercise for its greatest practitioner, Michael Phelps. 

The pool felt like a place of obligation, not joy, and thus Phelps walked away from the sport after bringing his record gold-medal total to 18 in London.

That dread was nowhere in evidence Thursday when Phelps made his triumphant return to competitive swimming after a 20-month retirement. Phelps beamed on the starting block before his first race, acknowledging the effusive roar he’d received from a sellout crowd at the Mesa Grand Prix. 

Then, he showed he could still swim a little bit. In a performance that wiped away any doubts about his form, Phelps posted the day’s fastest qualifying time in the 100-meter butterfly at 52.84 seconds. He improved his time to 52.13 seconds in the evening final but finished just behind longtime rival Ryan Lochte, who won in 51.93 seconds.

“I did what I wanted to do,” Phelps said after the final. “I said I wanted to be around 52.0, and I would be completely happy with that.” 

For a little perspective, Phelps won in 51.21 seconds at the 2012 Olympics and set the world record at 49.82 seconds in 2009. Japanese Olympian Takuro Fujii swam the fastest time in the world this year at 51.84 seconds. Phelps’ chief butterfly rival from 2012, South African Chad le Clos, won in 51.06 seconds at last year’s World Championships. 

Phelps windmilled his arms in familiar fashion before bursting into the water for his first race. Just after the 50-meter turn, his blue and white North Baltimore Aquatic Club cap bobbed at the front of the pack.

“I could tell when he came in and I first saw him warm up that it was going to be good, that he was into it,” said Phelps’ longtime coach Bob Bowman.

After the race, Phelps described how he walked to the starting block early, as eager to jump in as he’d been when he was 10 years old.

“I felt like a summer league swimmer today,” he said. “I was standing up behind the block, and I just felt like I should have my heat and lane written on my hand in case I forget it.”

”It is funny that you went up there so early,” Bowman said.

“You know, I just didn’t want to wait anymore,” Phelps replied. “ I wanted to get up and get this first race done.”

Phelps seemed equally pleased to resume his friendly rivalry with Lochte. The two bantered playfully as Phelps stepped to the starting block.

“Him and I love racing each other,” Phelps said. “Obviously, neither of us wants the other to win, but that’s the best part of it. We get in and we leave everything in the pool every time we race each other.”

Lochte said he almost broke into a smile when he peeked over during the final and realized he was neck and neck with his old nemesis.

“Why, because you were ahead?” Phelps retorted.

Later, Lochte said he’d truly missed Phelps, who drives him like no one else. “Him leaving, it kind of broke my heart a little,” he said. 

Phelps did clear one minor hurdle, establishing a time that would qualify him for U.S. Nationals in August. “Yes!” he said semi-sarcastically, when the subject arose. He added that he hadn’t had to worry about a national qualifying time since he was 13.

Bowman rated Phelps’ first swim a better technical race than the final, when he missed a stroke on his turn. “By the time he got going, it was kind of like over,” Bowman said of the evening performance.

The buzzing crowd at the Skyline Aquatic Center attested to Phelps’ ongoing pre-eminence in the sport. No other swimmer could have created such an atmosphere, simply by showing up.