On a night characterized by endurance, drama and large doses of testosterone, the two central characters in the miniseries that has played out this week at the U.S. Olympic team trials in swimming competed in a combined five races and went head-to-head in one gripping 200-meter individual medley final.

In that race, Michael Phelps once again proved he is not a man to be counted out.

Thirty minutes after Ryan Lochte, who swam in three races, won the 200 backstroke final, Phelps, who contested two, kept Lochte from making it two gold medals in one night by narrowly upsetting him in a race in which he has won two straight world titles.

Phelps, the reigning Olympic champion, won the medley final in 1 minute 54.84 seconds as Lochte came home in 1:54.93. That gave Phelps a two-to-one edge over Lochte in finals this week, setting him up to enter the London Summer Games as the world’s most feared swimmer for the second straight Olympics.

“There are probably going to be some more races like that” between us, said Phelps, who turned 27 on Saturday. “It kinda seems like we play with each other; one person goes and then the other person goes. Ryan swam three great races tonight. That’s a tough triple.”

Phelps also competed in the semifinals of the 100 butterfly, posting the fastest time of the night. Lochte added the 200 back and the 100 fly semifinals, knocking off three races in one hour.

Phelps remains on pace to swim in five individual events and three relays in London; Lochte has secured his spot in four individual races and two relays with a hope of adding two more races before the meet is over.

“It’s probably the most pain I’ve tolerated in the sport of swimming,” Lochte said. “I took one at a time. The back was decent. I can go a lot faster in the IM. . . . The fly was, honestly, everything out there.”

At 8:15 p.m., Lochte dived in for the 200 backstroke final. He hit the first wall in sixth place, the second wall in third and the last in second, then methodically overtook Tyler Clary over the last 50 to take the title in 1 minute, 54.54 seconds as Clary touched the wall in 1:54.88. Rockville’s Jack Conger, 17, earned fifth place in 1:58.97.

Lochte caught his breath, swam to the side of the pool and climbed out, the first man on the deck at 8:17 p.m. With a wave of his hand to the crowd, he hurried off to the warm-down pool to prepare for his next race.

By 8:43 p.m., Lochte and Phelps filed out to wild applause from the CenturyLink Center crowd for the 200 medley final. At the start, Phelps made sure he got out fast, and unlike in the semifinals Friday, never surrendered the lead to Lochte. He led by .10 after the butterfly leg, .02 after the backstroke leg, and then inched in front on the breaststroke leg, getting up by .26 of a second.

“I kind of used Ryan having the 200 back to set the pace early,” Phelps said. “I know the 200 back is a very tough race. I know it takes a lot out of your legs.”

The freestyle leg brought out a brilliant sprint, as Lochte closed hard, pulling virtually even over the final meters. Phelps, however, powered ahead for the victory.

“It doesn’t really matter,” Phelps said. “The bigger races are a couple more weeks down the road. . . . The next [200 IM] is the one that counts.”

After the race, Lochte and Phelps shook hands and headed for the pool ladder. Phelps got out first; Lochte all but limped into the arena underbelly. Seventeen minutes later, Lochte stood in front of the crowd of 14,335 and accepted the gold medal for his performance in the 100 back.

“The best thing about swimming is racing and stepping up against the world’s best,” Lochte said to the crowd. “That’s what I love doing.”

Nine minutes after that, Lochte walked out to the deck for the final time. He finished third in his 100 butterfly heat in 52.47 — and tied for sixth overall. In the second heat, Phelps not only led with a time of 51.35, but also put up the fastest time in the world this year.

Though the 100 fly race is not even close to one of Lochte’s specialty events, he had good reason to contest it. A shoo-in to compete on the 4x100 and 4x200 relays in London, he hadn’t staked a claim to a spot in the 4x100 medley preliminaries or final. A top-two finish in the 100 fly final Sunday would give him that.

Though Phelps will be heavily favored, Lochte refused to concede anything.

“I’m never going up to the blocks to go second or third,” he said. “I’m going up to win it. [Sunday] I won’t have anything in between. My legs will be a little bit rested. Hopefully, I can put on a better show than I did today.”

In other news, Jessica Hardy clinched a redemptive Olympic team slot with her victory in the 100 freestyle in 53.96 as Missy Franklin earned a place in her third individual event. Franklin’s second-place effort in 54.15 gives her hope of winning at least six medals in London. Meantime, Natalie Coughlin, an 11-time Olympic medal winner, snagged a spot on her third Olympic team after missing on her first two tries. Coughlin finished sixth in the final in 54.44, giving her one of the six relay-team berths.

Anthony Ervin, 31, surprisingly posted the top time in the semifinals of the 50 freestyle nearly 12 years after he won an Olympic gold medal in the event. Ervin, who returned to the sport last year after retiring in 2003, touched the wall in 21.74 as Nathan Adrian, the 100 champion here, tied with Josh Schneider for the second-fastest time (21.81).

In the women’s 200 breast, Rebecca Soni claimed her second Olympic team berth with a victory in 2:21.13 as Micah Lawrence came in second in 2:23.03. Soni finished second in the 100 breast earlier in the week.