The German parliament has backed a new law to allow the recreational use of cannabis.
Under the law, over-18s in Germany will be allowed to possess substantial amounts of cannabis, but strict rules will make it difficult to buy the drug.
Smoking cannabis in many public spaces will become legal from 1 April.
Possession of up to 25g, equivalent to dozens of strong joints, is to be allowed in public spaces. In private homes the legal limit will be 50g.
Already police in some parts of Germany, such as Berlin, often turn a blind eye to smoking in public, although possession of the drug for recreational use is illegal and can be prosecuted. Use of the drug among young people has been soaring for years despite the existing law, says Health Minister Karl Lauterbach, who is instigating the reforms.
He wants to undermine the black market, protect smokers from contaminated cannabis and cut revenue streams for organised crime gangs.
But legal cannabis cafes will not suddenly spring up all over the country.
A ferocious debate about decriminalising cannabis has been raging for years in Germany, with doctors' groups expressing concerns for young people and conservatives saying that liberalisation will fuel drug use.
After a stormy session on Friday in the Bundestag, Germany's parliament, the vote was eventually passed by 407 votes to 226.
Simone Borchardt of the opposition conservative CDU told MPs that the government had gone ahead with its "completely unnecessary, confused law" regardless of warnings from doctors, police and psychotherapists.
But Mr Lauterbach said the current situation was no longer tenable: "The number of consumers aged between 18 and 25 has doubled in the past 10 years."
After the vote he said the law would "dry out the black market" and fix "a failed drug policy".
As so often in Germany, the law approved by MPs is complicated.
Smoking cannabis in some areas, such as near schools and sports grounds, will still be illegal. Crucially, the market will be strictly regulated so buying the drug will not be easy.
Original plans to allow licensed shops and pharmacies to sell cannabis have been scrapped over EU concerns that this could lead to a surge in drug exports.
Instead, non-commercial members' clubs, dubbed "cannabis social clubs", will grow and distribute a limited amount of the drug.
Each club will have an upper limit of 500 members, consuming cannabis onsite will not be allowed, and membership will only be available to German residents.
Growing your own cannabis will also be permitted, with up to three marijuana plants allowed per household.
This means that Germany could be in the paradoxical position of allowing possession of rather large amounts of the drug, while at the same time making it difficult to purchase.
Regular smokers would benefit, but occasional users would struggle to buy it legally and tourists would be excluded. Critics say this will simply fuel the black market.
Over the next few years, the government wants to assess the impact of the new law, and eventually introduce the licensed sale of cannabis.
But given how tortuous the debate has been so far, nothing is certain.
Meanwhile, opposition conservatives say that if they get into government next year, they will scrap the law entirely. Germany is unlikely to become Europe's new Amsterdam anytime soon.