Rio de Janeiro mayor Marcelo Crivella was arrested on Tuesday as part of a corruption investigation just nine days before the end of his term in office.
The judge leading the investigation, Rosa Helena Penna Macedo Guita, called him "the head of a criminal organization ... installed within the Rio mayor's office with the aim of obtaining illicit profits in the most varied ways."
After a two-hour hearing, she ordered him held in custody and television footage later showed him being transferred to a prison in the city's north.
Hours later a judge granted permission for the mayor to be held under house arrest, but Crivella will have to wear an electronic ankle bracelet, submit all his telephone and computers and not have any contact with third parties.
GloboNews television channel had broadcast footage of police arresting the mayor at his home in the upscale Barra de Tijuca neighborhood just before 6 am.
"I'm the mayor that's done the most against corruption in Rio de Janeiro. I ask that justice be served," said Crivella.
He received support from far-right President Jair Bolsonaro at the municipal elections in November but was soundly beaten.
Crivella claimed to be the victim of "political persecution."
Several other people were also arrested as part of the same operation including businessman Rafael Alves, the suspected mastermind.
He is the brother of Marcelo Alves, president of municipal tourism agency Riotur.
Mauro Macedo, Crivella's former campaign treasurer, was also arrested.
He is the cousin of evangelical preacher Edir Macedo, who is also Crivella's uncle.