The presence of benzoylecgonine — the drug's main byproduct — was detected during a test in January.
Larsen, who most recently played for Adelaide United, was provisionally suspended in March while an investigation was conducted by the Australian Sports Anti-Doping Authority (ASADA).
The Dane has since left the club and was on Friday slapped with a lengthy ban.
“Football Federation Australia has imposed a period of suspension of two years, to run from the date of Mr Larsen's provisional suspension,” the governing body said.
The ASADA verdict noted that Larsen did not take the prohibited substance with the intention of improving his sporting performance.
The 32-year-old joined Adelaide last year after a stint in Malaysia following a career spent mostly in Denmark and Germany, where he featured for teams including FC Midtjylland and Fortuna Düsseldorf.
He will quit football altogether following the ban.
“It wasn’t a calculated decision to make me a better football player. On the contrary, it was a lousy decision I made in a vulnerable moment,” he told the Danish Football Players' Association.
“In Australia, the loneliness became too overwhelming, and in an attempt to escape reality for a moment, I made a lousy decision. I regret it, but I also stand by my action and will live with the consequences.
“Obviously, this wasn’t the way I thought I would end my professional career. But it is what it is. Now I am looking forward, and the time has come to my life after football. I’ve just started studying and I will use the coming time to find out what I want to do with the rest of my life,” he added.