Ryan Lochte poses with volunteers at the swimming venue Saturday night. Hours later, he was a victim of an armed robbery with three other U.S. swimmers. (Jonathan Newton/The Washington Post)

The three other U.S. swimmers were lying on the ground, following their assailant’s orders, when the gunman turned to Ryan Lochte, one of Team USA’s charming stars.

“I’m not getting on the ground,” Lochte said, as he recounted to NBC News the story of the armed robbery he endured early Sunday morning. “And then the guy pulled out his gun, he cocked it, put it to my forehead and he said, ‘Get down,’ and I put my hands up. I was like, ‘Whatever.’ ”

The four swimmers on the U.S. Olympic team lost their money and wallets but otherwise escaped unharmed from the gunmen who were posing as police officers. The harrowing assault, however, amounts to the most serious breach of security against American athletes in these Olympics, and it follows a troubling pattern of robbery, gunfire and assaults that call into question the ability of Brazil's security forces to keep participants and fans safe.

For a city on high alert for foreign-born terrorism, it has been the everyday domestic crimes that have disrupted the Olympics. While police and security officials say the city's overall crime rate fell during the first week of the Games, helped by more than 80,000 soldiers and police deployed on the streets around stadiums and along bus routes, thieves have managed to prey on several Olympic participants and high-profile officials, even in tourist-friendly areas and near Olympic venues.

Lochte, who won a gold medal as part of a relay in these Games, had been traveling home in a taxi, heading to the Olympic Village after a dance party, along with teammates Gunnar Bentz, Jimmy Feigen and Jack Conger, when the robbery took place, according to the U.S. Olympic Committee. Lochte told NBC that after the taxi pulled over, men approached them with a police badge.

“They pulled out their guns. They told the other swimmers to get down on the ground — they got down on the ground,” Lochte said. “I refused. I was like, we didn’t do anything wrong, so — I’m not getting down on the ground.” After the man threatened him with the gun, Lochte said, “He took our money, he took my wallet — he left my cellphone, he left my credentials.”

The four swimmers made it home unharmed. One of the swimmers, Conger, who is from Rockville, “is safe and in Rio,” his mother, Bridget, said.

“We are all safe,” Bentz tweeted. “Thank you for your love and support.”

“P.S. The gold medal is safe,” he added.

After four Olympics, Lochte, 32, has established himself as one of the more colorful athletes representing the United States. On the medal stand during the London Olympics, he flashed a custom-made American flag dental grill. This time, he died his hair silver for the Games. Lochte has the reputation as a bon vivant but has also emerged as an elder statesman with the swim team. He has won six gold medals over the years, including one in Rio for the 4x200-meter freestyle relay. Lochte has not been in an event since Thursday, and swimming ended Saturday night.

Michael Phelps, already the most-decorated Olympian of all time, just keeps adding to his personal medal total at the Rio Games. (Video: Jayne W. Orenstein/The Washington Post/Photo: Jonathan Newton/The Washington Post)

Late in the evening, Lochte attended a party with Brazilian swimmer Thiago Pereira and Pereira’s wife, Gabriela Pauletti, to celebrate the birthday of a mutual friend inside Club France, situated along the Rodrigo de Freitas Lagoon in an upscale neighborhood of Rio, according to Flavio Perez, a representative for Pereira. Some 2,500 attended the DJ’ed dance party, which began around 11:30 p.m. and took place in a venue inside the club called the Picadeiro Armando de Alencar. Lochte posted a brief video of the crowd on social media.

A spokesman for Club France, Hugo Sppezapria, said Lochte and Pereira left the party together between 2:30 a.m. and 3 a.m. But Perez said Pereira and his wife went back to their hotel earlier. It is unclear whether the other three U.S. swimmers attended the party or met up later.

The armed robbery came as the swimmers were driving back to the Olympic Village in western Rio.

“While it is true that my teammates and I were the victims of a robbery early Sunday morning, what is most important is that we are safe and unharmed,” Lochte tweeted Sunday evening.

Brazilian police said they were investigating the robbery and would be interviewing the athletes. After interviewing one of the swimmers, police said in a statement that the athletes had been returning from the party in the taxi when they were robbed but “the victim did not know where the robbery happened.” One police officer, speaking on the condition of anonymity, said that taxi drivers often work with other criminals to facilitate robberies. The prospect of thieves dressed as police is more unusual, the officer said.

“It’s not common, but it happens. It’s not every day,” said the officer, who had not been briefed on the incident. “From my point of view, the taxi driver was involved. Very possible.”

During the Games, a spate of robberies has demonstrated the dangers of Rio de Janeiro. On the night of the Opening Ceremonies, the government’s head of security for major events was mugged by a gang of thieves outside Maracanã stadium. Two Australian rowing coaches were robbed at knifepoint near Ipanema Beach, and Portugal’s education minister was also assaulted near the same lagoon where Lochte attended the party. A security officer for the Olympics was shot and killed in a favela. A stray bullet has hit a media tent, and an Olympics bus had its windows smashed by rocks or bullets.

Rio de Janeiro has suffered a rising homicide rate this year as the economy has plunged into a severe recession.

Boren reported from Washington. Dave Sheinin in Rio de Janeiro contributed to this report.