Cannabis use for recreational purposes in Canada will be legalised this autumn, Justin Trudeau has said.

The country's parliament passed a law legalising the drug on Tuesday, which the prime minister said would shift the market for the drug away from organised crime and protect the nation’s youth.

Canada is only the second country in the world to make cannabis legal nationwide.

“The legislation is transformative,” said justice minister Jody Wilson-Raybould, who said the move “marks a wholesale shift in how our country approaches cannabis, leaving behind a failed model of prohibition”.

The Cannabis Act passed its final hurdle by 52 votes to 29 in the Senate.

The federal government had said provincial and territorial authorities will need eight to 12 weeks following the bill’s and royal assent to prepare for retail sales.

“It is our hope as of 17 October there will be a smooth operation of retail cannabis outlets operated by the provinces with an online mail delivery system operated by the provinces that will ensure that this happens in an orderly fashion,” Mr Trudeau said.

He added: “Over the following months and indeed years we will completely replace or almost completely replace the organised crime market on that.”

Uruguay became the first country to legalise cannabis in 2013, while a number of US states have also voted to permit recreational use of the drug.

Canada’s federal government is to publish regulations that will govern the trade, but each province will work up its own rules for cannabis sales.

Many questions remain unanswered, including how police will test motorists suspected of driving under the influence, what will happen to previous cannabis-related convictions, and the rules on home cultivation.

The provinces of Quebec and Manitoba have already decided to ban home-grown cannabis, even though the federal bill specifies that individuals can grow up to four plants per household.

“Provinces can set their own laws. If individuals are challenging that law, they can challenge it,” Ms Wilson-Raybould said.

Mr Trudeau’s government will not discuss pardons of past convictions until legalisation is in effect.

“There’s no point looking at pardons while the old law is in the books,” he said.

Cannabis around the world Show all 13 1 /13 Cannabis around the world Cannabis around the world Morocco Farmers destroy cannabis plantations under Moroccan police supervision in the northern Moroccan Larache region, pictured here in 2006 AFP/Getty images Cannabis around the world Colorado Growing business: Cannabis on sale at River Rock Wellness Sam Adams Cannabis around the world Oakland Oaksterdam in Oakland, California, is the world's only university dedicated to the study and cultivation of cannabis Alain Jocard/AFP/Getty Images Cannabis around the world Seattle A cannabis smoker marks the start of the new law by the Space Needle in Seattle Getty Images Cannabis around the world China Cannabis growing wild in China, where it has been used to treat conditions such as gout and malaria Cannabis around the world Uruguay Uruguay has voted to make the country the first to legalize marijuana AFP/Getty Cannabis around the world Colorado A groundswell of support from the public led to full legalisation in Colorado Getty Images Cannabis around the world Berlin A man smokes licenced medicinal marijuana prior to participating in the annual Hemp Parade, or 'Hanfparade', in support of the legalization of marijuana in Germany on August 7, 2010 in Berlin, Germany. The consumption of cannabis in Germany is legal, though all other aspects, including growing, importing or selling it, are not. However, since the introduction of a new law in 2009, the sale and possession of marijuana for licenced medicinal use is legal. Sean Gallup/Getty Images Cannabis around the world UK The UK latest figures show 2.3 million people used cannabis in the last year AP Cannabis around the world Amsterdam Tourists visiting Amsterdam will not be banned from using the city’s famous cannabis cafes Getty Images Cannabis around the world Merseyside These 25 cannabis plants, seized in Merseyside police, could have generated a turnover of £40,000 a year Cannabis around the world San Francisco April 20, 2012: People smoke marijuana joints at 4:20 p.m. as thousands of marijuana advocates gathered at Golden Gate Park in San Francisco, California. The event was held on April 20, a date corresponding with a numerical 4/20 code widely known within the cannabis subculture as a symbol for all things marijuana. Reuters Cannabis around the world Spain A cannabis users' association will pay the town of Rasquera more than €600,000 a year for the lease of the land

The move comes as Theresa May faces calls to legalise cannabis in Britain, with former foreign secretary William Hague declaring the war on the drug “comprehensively and irreversibly lost”.

The UK government is reviewing the medical use of the drug following two cases in which children with epilepsy were denied cannabis oil that their parents said had prevented them having seizures.

In the US, nine states and the District of Columbia have legalised marijuana.

California, home to one in eight Americans, launched the country’s biggest legal marijuana marketplace on 1 January.

Canada’s legalisation of cannabis was greeted with enthusiasm by campaigners and businesses in the US.

Don Hartleben, who manages Dank of America, a retail cannabis store just south of the border in Blaine, Washington, said Canada’s legalisation would bring a potential business boom.

Many of his customers are Canadian tourists who are terrified of trying to bring pot across the border, he said.