MONTEVIDEO, Uruguay — Uruguay has approved pioneering legislation legalizing marijuana, becoming the first nation in the world to oversee the production and sale of the drug.

After a 12-hour debate, 16 leftist senators out of 29 lawmakers voted Tuesday in favor of the legislation championed by President Jose Mujica, who must now sign it into law.

Outside the Senate, hundreds of cannabis-smoking supporters set off fireworks in what they dubbed "the last march with illegal marijuana." The atmosphere was festive.

"The war against drugs has failed," said Senator Roberto Conde as he presented the bill on behalf of the ruling leftist Broad Front, calling it an "unavoidable response" to that failure.

"It is an historic day. Uruguay is now on the international forefront of this issue," said ruling party senator Alberto Couriel.

The bill passed the lower house of Congress in August and was assured of approval because the ruling coalition controls both chambers.

It authorizes the production, distribution and sale of cannabis, allows individuals to grow their own on a small scale, and creates consumer clubs — all under state supervision and control.

Mujica, a 78-year-old former leftist guerrilla fighter, has called his plan an experiment. "There are a lot of doubts and the doubts are legitimate," he told Channel 4 television before the vote.

"But doubts shouldn't paralyze us in trying new paths to deal with this problem that has gripped us."

However, he added: "We are not totally prepared. But as in everything, you have to give it a chance."

The legislation has caused unease in neighboring Brazil and Argentina.

The bill goes well beyond the marijuana legalization measures recently approved by Colorado and Washington state, or the similarly liberal laws of the Netherlands and Spain.

Consumers over 18 will be able to grow their own marijuana, though no more than six plants per person. They can also get it through clubs or buy up to 40 grams per month from pharmacies.

In every case, they must be registered with the government.

Conde argued that the law strikes a balance between individual liberty and public health, while also resolving the "grotesque juridical inconsistency" arising from the status quo, in which marijuana consumption is not penalized but its production and sale is.

"Another blow against social hypocrisy," said a smiling Valeria Rubino, a 37-year-old who took part in Tuesday's "last march."

Opposition parties rejected the measure, as did pharmacists, who reject the idea that marijuana will now be sold in drug stores.

There is also widespread public skepticism in this small country of 3.3 million. A poll taken in September found 61 percent disapprove of the law.

Legalizing cannabis will "diminish the perception of risk and foster consumption, especially among children and adolescents," said Senator Alfredo Solari of the opposition Colorado Party.

"Neither our government nor the rest of the world should experiment with Uruguayans," he said.

Uruguayan psychiatrists were divided over the measure. Some argue it will help tamp down the use of more dangerous drugs, while others say it trivializes marijuana's harmful effects.

Not all users were in favor of the law, either, with some chafing at the government controls.

"It's invasive, because it is not up to the government to determine how much marijuana can be consumed and the quality," said Alicia Castilla, the author of a book on "Cannabis Culture" who spent three months in jail for growing the drug at home.

In a region where the war on drugs has claimed thousands of lives, the Uruguayan initiative won the support of former Latin American presidents who served on the Global Commission on Drug Policy.

But the International Narcotics Control Board, which oversees the implementation of international treaties on drugs, has warned that it violates the Single Convention of Narcotic Drugs, adopted in 1961 by Uruguay and 185 other countries.

The government has accompanied action on the law with a publicity campaign featuring the slogan, "All drug consumption has risks."

Conde said the law deals with an already entrenched social reality.

"Marijuana is the illegal drug that is most consumed, fundamentally by young people, one that is perceived as extremely low risk and is easily obtained," he said.

Consumption of cannabis has doubled here in the past decade, and now accounts for 70 percent of the illegal drug consumption in Uruguay.

The government estimates that 128,000 of the country's inhabitants smoke cannabis, though marijuana consumer associations put the number at around 200,000.