RIO DE JANEIRO — Call him "the wandering inmate," or the "prisoner without a cell." Brazilians know him as Fernandinho Beira Mar, or Freddy Seashore. Apparently there is no prison in the country strong enough to hold him for very long.

On Thursday, the inmate, whose real name is Luiz Fernando da Costa, walked out of the highest-security prison in Sao Paulo, Brazil's biggest state, where authorities said they could no longer hold him safely. Governors of several other Brazilian states had declared they could not or would not take him.

Under heavy guard, Da Costa was taken to another location, which remained a state secret for several hours, the latest chapter in a long-running drama involving the nation's most dangerous inmate. His case is speeding up efforts to create a system of maximum-security federal prisons here for the first time.

"Nobody wants him, what can we do?" said Alicia Felicia Linhares, a spokeswoman for Justice Minister Marcio Thomaz Bastos. "Maximum-security prisons were not the minister's priority when he came to office. But confronted with the security crisis in Rio, he understood the need for them."

Captured in Colombia, Da Costa was first held in Brasilia and then transferred to Rio, the city where got his start as a drug trafficker. After being convicted, he ran rampant inside Rio's toughest prison, the Bangu I. In September, Da Costa and his cohorts took over the facility for 23 hours, killing his most important rivals, including one who was set on fire. Then, in February, just as Rio was preparing for Carnaval, members of Da Costa's "Red Command" crime syndicate went on a citywide crime spree, forcing businesses to shut down in deference to their leader.

Rio lived in terror for four days. Members of the Red Command destroyed 55 buses and forced business closings in 20 neighborhoods, including the fashionable Ipanema district. It was violence financed, authorities said, by the vast drug empire Da Costa still controls.

On Feb. 27, Da Costa was transferred to a prison in Sao Paulo state. Authorities there tried to restrict his privileges, which included sunbathing and takeout meals from restaurants. Two weeks later, a top official at the prison -- Judge Antonio Jose Machado Dias -- was gunned down in a gangland-style shooting.

Authorities suspect the assassination was carried out by a Sao Paulo crime syndicate with strong ties to Da Costa's Red Command.

With Sao Paulo authorities saying they could hold Da Costa for only 30 days, several states refused a federal request to take him next.

Rio's governor said Da Costa could not return there. Jorge Viana, the governor of remote Acre state on the Bolivian border said: "I don't have the facilities. Prisoners like him should be close to the urban centers. You can't just hide garbage under the rug."

Brazilian prisons are run by the governors of Brazil's 26 states and its federal district, Brasilia. Last year, during his successful campaign for the presidency, Luiz Inacio Lula da Silva called for the establishment of maximum-security federal prisons.

"Dangerous people like Fernandinho Beira Mar should [be] under the responsibility of the federal government," said the man known here as Lula. "He should not have access to the things he has, or be able to order crimes from within prison. He needs to be effectively isolated."

On Wednesday, Justice Minister Bastos said the first federal, maximum-security prison will be up and running in 30 to 40 days, thanks to a quick upgrade of a facility already under construction in the northern state of Piaui.

Da Costa might be housed in the new facility when it opens. But on Thursday, his odyssey through the Brazilian penal system took him elsewhere.

Hustled out of his Sao Paulo cell in an elaborate operation just after 7:30 a.m., Da Costa was flown to Brasilia, where his plane stopped for refueling. By early afternoon, federal authorities still had not disclosed his destination. Then, in the afternoon, wire reports said he was headed for the northeastern state of Alagoas. President Lula had intervened, the reports said, asking the governor of Alagoas to take the inmate. But government officials would not confirm his destination.

Da Costa's lawyer said Thursday that her client should serve his sentence in the state in which he was convicted. She said it was unfair to punish him for the incompetence of Rio's prison guards.

"If the government can't find competent agents, if they are corrupt, then that's a problem of the government," said the lawyer, Cecilia Machado. "They have to pay their officers better."