Members of Uruguay's House of Representatives have passed a bill to legalise marijuana.

If it goes on to be approved by the Senate, Uruguay will become the first country to regulate the production, distribution and sale of marijuana.

The measure is backed by the government of President Jose Mujica, who says it will remove profits from drug dealers and divert users from harder drugs.

Under the bill, only the government would be allowed to sell marijuana.

The state would assume "the control and regulation of the importation, exportation, plantation, cultivation, the harvest, the production, the acquisition, the storage, the commercialisation and the distribution of cannabis and its by-products".

Buyers would have to be registered on a database and be over the age of 18. They would be able to buy up to 40g (1.4oz) per month in specially licensed pharmacies or grow up to six plants at home.

Foreigners would be excluded from the measure.

Political tussle The bill was approved by 50 of the 96 MPs in the lower house following a fierce 13-hour debate in the capital, Montevideo.

The supporters of the measure argued that the fight against drugs and drug trafficking had failed, and the country needed "new alternatives".

"The regulation is not to promote consumption; consumption already exists," said Sebastian Sabini of the governing centre-left Frente Amplio (Broad Front) coalition, which has a majority of one in the lower house.

Marijuana use has reportedly doubled in Uruguay over the past year. An estimated 22 tonnes of marijuana are being sold in the country annually, according to Uruguay's National Drugs Committee.

But Gerardo Amarilla of the opposition National Party said the government was "playing with fire" given the health risks he said were linked to marijuana use.

All eyes were on Dario Perez, a member of the governing coalition but a strong opponent of the bill, whose vote could have scuppered the bill.

During his 20-minute speech, Mr Perez reiterated his belief that the issue should be put to a referendum and not have been "imposed" by the government.

But to applause by supporters of the bill in the public gallery, he finally concluded that as long as he was a member of the coalition, he would vote with it, despite his personal misgivings.

The bill is now expected to be approved by the Senate, where the left-wing government has a bigger majority.

But opposition politicians said that even if the law made it through the senate, they would launch a petition to have it overturned.

A survey carried out before the vote by polling organisation Cifra suggested 63% of Uruguayans opposed the bill.

Papal opposition The progress of the bill is being watched closely across the region, says BBC regional analyst Ignacio de los Reyes.

For decades, drug trafficking has caused tens of thousands of deaths throughout Latin America.

Uruguay may have not experienced the bloodshed caused by drug trafficking, but the proposal could be seen as a test for violence-torn nations looking for an end to their drug wars, our analyst adds.

The vote also comes just days after Pope Francis criticised drug legalisation plans during a visit to neighbouring Brazil.

The pontiff said it was "necessary to tackle the problems which are at the root of drug abuse, promoting more justice, educating the youth with the values that live in society, standing by those who face hardship and giving them hope for the future".