Denver on Wednesday became the first US city to decriminalise psychedelic mushrooms, as voters approved a ballot initiative by a razor thin margin.

The new ordinance loosens restrictions on the personal use and possession of psilocybin mushrooms, also known as "magic mushrooms," by people over the age of 21.

The new law, however, does not make it legal to buy, sell or possess the drug. It instructs police officers to treat psilocybin users as their lowest priority.

Although the measure earlier appeared headed for defeat, by late afternoon on Wednesday the numbers showed a reversal of fortune with Initiative 301 set to pass with nearly 50.6 percent of the vote.

"It's been one hell of a 21-and-a-half hours," Kevin Matthews who led the decriminalization campaign, told The Denver Post after the vote results were announced.

"If these results hold, this is an example of the absurd comedy of the great metaphor. Against all odds, we prevailed. This is what happens when a small team of dedicated and passionate people unite under a single idea to create change."

Officials said the vote would be certified on May 16 once all military and overseas ballots have been counted.

Proponents of the new law point to studies that say psilocybin is not considered addictive and could be used against depression or opioid addiction, which causes thousands of deaths in the US each year.