Ryan Lochte made up the story that he and three other US Olympic swimmers were robbed at gunpoint, so they could cover up an altercation with a gas station security guard after busting down a bathroom door, authorities said Thursday.

Brazilian authorities have closed-circuit video of the brouhaha involving American gold-medal swimmers Lochte, Jack Conger, Gunnar Bentz and Jimmy Feigen and a rent-a-cop, officials said.

“One of the swimmers was seen on CCTV footage breaking down the door to the bathroom at the gas station and fighting with a security guard” on the night of the incident, a Brazilian police official said.

Conger and Bentz, who were pulled off a US-bound plane Wednesday night, gave up Lochte to cops and said he fabricated the robbery tale, a police official told ESPN.

The incident unfolded when the swimmers, going home after a night of partying, stopped at a gas station shortly after 6 a.m. Sunday to use the bathroom — but it was locked, police officials told the Associated Press.

The swimmers then broke down the door and were confronted by an armed security guard, although he never drew the weapon, authorities said.

And at one point in their visit to the gas station, swimmers urinated outside the bathroom, a station manager told O Globo newspaper.

With the help of a customer who acted as translator, the station manager demanded the swimmers pay for the busted door — which they did before leaving, cops told AP.

Rio police chief Fernando Veloso said the swimmers should apologize to city residents for lying.

“The only truth that they told was that they were drunk,” Veloso.

O Globo published security video that appears to show the swimmer being chased out of a bathroom area — but didn’t show any urination.

They tried to jump into a yellow taxicab before they were stopped, walked out and appeared to offer money, the video showed.

When the US swimmers first reported the incident, they were too drunk to give even the most basic details, such as the number of the alleged robbers, ABC reported.

Conger and Bentz were set to jet out of Rio de Janeiro airport Wednesday night before they were grounded in Brazil.

They were held for four hours late Wednesday and early Thursday before being released.

Three US consular officials and a Brazilian attorney rushed to meet Conger and Bentz at the airport, and told them to keep their mouths shut for now, according to Brazil’s largest newspaper, Folha de Sao Paulo.

“They were very shocked and did not understand why they were refused passage (out of Brazil),” said the athletes’ defense lawyer, Sergio Guerra.

“My clients were taken off the plane and told to make a statement which is an aberration of justice. What’s causing me great shock is the retention of the passports of these witnesses.”

Feigen had also been set to fly out Wednesday but didn’t show up for his flight.

Lochte had already flown home to the US on Monday, a police spokesman said.

Feigen has been in contact with police, and all three men planned to meet with Brazilian law enforcement Thursday, according to USOC spokesman Patrick Sandusky.

The US State Department urged the swimmers to cooperate with Brazilian officials.

Additional reporting by Sophia Rosenbaum