Plumes of fire burst forth suddenly out of both sides of the pool during the 400-meter individual medley final Monday night, an appropriate — if quite unexpected — mechanized accent to what was happening in the water just below.

In the opening final of the U.S. Olympic Team trials in swimming, the world’s top two swimmers pushed each other in a gritty, heated fight both for preeminence in the event, and something more basic: coveted berths of the U.S. Olympic team.

In the end, Ryan Lochte, the reigning world champion in the event, held off Michael Phelps, the reigning Olympic champion, as both claimed Olympic team slots while fending off a powerful early push by Tyler Clary, who led at the race’s halfway point but faltered in the end.

Lochte pulled away during the breaststroke leg, winning in 4 minutes 7.06 seconds as Phelps touched the wall in 4:07.89. Both men hovered in the pool after the race, chests heaving, expressionless, before shaking hands. The victory gave Lochte a boost entering the London Games, where he will try to upend Phelps’s quest to earn a third straight gold medal in the event.

“It’s a rivalry we’ve had for almost eight years now,” said Lochte, who had never beaten Phelps in the event before. “We’ve just been swinging back and forth. It’s hard to say who the best swimmer is, because we’re both such great racers.”

Lochte and Phelps could face off here again in the 200 freestyle, the 200 individual medley and possibly the 100 freestyle. Phelps is also likely to swim the 100 and 200 butterflies; while Lochte will add the 200 backstroke and possibly another event. Lochte will attempt in London to dethrone Phelps as the world’s most accomplished, versatile swimmer, as both men seek this week to put themselves in position to win as many as eight gold medals.

Clary claimed the unlucky third spot, finishing in 4:09.92 after leading after the backstroke leg. Only the top two finishers in each event here win Olympic team berths.

In the night’s other finals, Elizabeth Beisel won the women’s 400 medley in 4:31.74 as Caitlin Leverenz claimed second in 4:34.48; and Peter Vanderkaay won the 400 freestyle in 3:47.67 as Conor Dwyer got second in 3:47.83.

“All three of us were side by side by side, neck and neck and neck,” Phelps said about the 400 medley. “You could hear the excitement from the crowd. I think that was something that played a role in giving me extra energy in the last 50.”

The swimmers were greeted by a roaring, standing, stomping crowd when they walked onto the pool deck of the CenturyLink Center for the first final of these Olympic trials. Lochte and Phelps emerged from the bowels of the arena with heads down, grim faces.

Neither acknowledged the fans, even while applause thundered down when their names were announced.

After winning the 400 IM while setting a world record at the 2008 Summer Games, Phelps had declared that he was through with the taxing event. But after alternately toying with it and abandoning it in exasperation, Phelps decided to resurrect it for these trials.

It’s been one of his signature races, and one that his mother and longtime coach all but begged him to take up again. And because it’s the opening event on the opening day of the Olympic schedule, it conflicts with none of the other events Phelps wishes to swim.

But it’s the most painful event on Phelps’s calendar and he openly detests it, even while finding the challenge impossible to resist.

“I wanted to do that,” Phelps said. “Having a year and a half off from it was good, but this is an event I’ve done for a long time [and] it’s something I’m kind of happy to finish off my career with.”

Though Phelps made the decision to compete in the 400 medley back in late March, he coyly declined to make a public commitment to the event until Sunday. Bob Bowman, Phelps’s coach at the North Baltimore Aquatic Club, backed Phelps’s decision, saying the event is a good one for Phelps because it helps him prepare to swim a host of other events.

“This is the catalyst for everything else,” Bowman said. “When this goes, everything else goes well. . . . Everything else falls in line when he’s training for the 400.”

Bowman predicted Phelps would get faster in the event before the Olympic Games, simply because he did not execute well Monday.

“His turns were horrendous,” Bowman said. “That’s two seconds there. Any number of things he can work on.”

While Phelps largely shelved the 400 medley over the last few years, Lochte usurped his domination, winning the event at the past two world championships and the 2010 Pan Pacific Championships.

After claiming the bronze in the event and the 200 medley at the 2008 Summer Games, Lochte said, he decided enough was enough.

He wanted to climb to the top perch of medal podiums, not the second or third.

He said Monday he was in the best shape of his life here and expected to get faster throughout the week.

Lochte’s coach, Gregg Troy, said Lochte, too, could cut a few seconds from his time by cleaning up certain aspects of his race. Lochte agreed, saying the “time was not good at all. I know I’m capable of going way faster.”

“Obviously, he’s pretty good competition,” Bowman said. “He just kicked our [butt].”