BRASILIA (Reuters) - A Brazilian Supreme Court justice called on Friday for the legalization of marijuana and even cocaine to undo the growing power of drug gangs behind a wave of violence that has shaken Latin America’s largest country.

A man shows a bag with marijuana, marked C.V. for Comando Vermelho (Red Commando), inside a favela in Rio de Janeiro, Brazil June 24, 2016. Picture taken June 24, 2016. REUTERS/Nacho Doce

Justice Roberto Barroso, a Yale graduate and constitutional law professor, said 50 years of war against drugs had failed miserably, clogging jails with small-time dealers and fueling a violent gang battle for control of the lucrative trade.

“Unlike the United States and Europe where the problem lies in the impact drugs have on consumers, in Brazil the problem lies in the power drug traffickers have over poor communities,” Barroso told Reuters in the court’s modern glass building in Brasilia.

“I can assure you it is only a matter of time. Either we legalize marijuana now or we do it in the future after we have spent billions and incarcerated thousands.”

The rare appeal from a top judge in the deeply conservative country reflects rising fears about the violence plaguing Brazil’s overcrowded prisons and city slums.

A New Year’s day prison massacre in the jungle city of Manaus in which inmates from one drug gang decapitated dozens of rivals sparked jail riots across the country.

This week, a strike by police in Brazil’s southeastern state of Espirito Santo unleashed a crime frenzy that killed more than 120 people - many of them linked to criminal gangs, according to police unions.

Regulating the production, sale and consumption of marijuana - as in Brazil’s smaller neighbor Uruguay - could be first step in curbing crime in one of the world’s most dangerous countries, Barroso said.

“If that works we can easily move to legalize cocaine,” said Barroso, who as a lawyer pushed to legalize stem cell research and gay rights. “If you want to break the power of traffickers you need to consider legalizing cocaine.”

In 2013, Uruguay become the first country in the world to legalize marijuana. Few countries have decriminalized the possession of cocaine, with experts divided over the practicality of legalizing one of the most addictive illegal drugs.

DIVIDED COUNTRY

While many Latin American peers have decriminalized possession of marijuana for consumption, Brazil remains divided.

Barroso is one of three judges on the 11-member Supreme Court who recently voted in favor of decriminalizing marijuana in a case that he hopes could eventually pave the way for legalization.

A rising number of Brazil’s conservative and evangelical politicians are vowing a tougher stance on drugs, however.

Drug use has skyrocketed in Brazil, the second-biggest consumer of cocaine after the United States, according to the United Nations.

Since the approval in 2006 of a law that gives judges discretion to determine who is a drug consumer and who is a dealer, the prison population has surged 55 percent. With more than 622,000 inmates, it is the fourth largest in the world.

One in every four male inmates was convicted for drug trafficking, by far the most common conviction, according to justice ministry data.

“I’m not sure if my proposal for legalization will work, but I’m sure that the war on drugs has not,” Barroso said. “We cannot just keep repeating the same mistakes over and over again.”