Mr Biagi, who served as local government minister, stepped down from Holyrood in 2016.
He said at the time that he told First Minister Nicola Sturgeon and Deputy First Minister John Swinney he was leaving for "health reasons" but did not go into detail.
Mr Biagi said he had "binged on food" and "drank alone", adding: "One night at home I vomited while passed out and may well have avoided choking on it by the luck of having fallen on my side rather than my back."
In a candid series of tweets on World Mental Health Day, he revealed that he had been diagnosed with major depression in 2002, and had tried to kill himself that Christmas.
He said he was "suicidal on many occasions throughout 2002 and 2003" and was held by the police for a night in July 2003 "because I was suspected of being a risk to myself".
His mental health improved, and he was elected to the Scottish Parliament in 2011, recalling: "My spirits had never been higher. It seemed like the ultimate disproving of all the things I had thought those years before when I was sure nothing would ever get better."
But he added that the routines that had previously helped him were "disrupted" by his new life at Holyrood.
He recalled: "Listening to evidence of child neglect in an Education Committee inquiry, for example, was harrowing. It took a toll. I began to lapse into old patterns.
"I always kept my suit jacket on and wore coloured shirts because I didn't want anyone seeing my arms. I binged on food. I drank alone.
"One night at home I vomited while passed out and may well have avoided choking on it by the luck of having fallen on my side rather than my back."
The former MSP, who began a PhD in political sciences at Yale University in 2016, said he had "never known exactly how much this was all an open secret around Holyrood".
Mr Biagi continued: "My mental health was the real reason I stepped down. I thought I owed the people I represented more than I could deliver. I owed my colleagues more too.
"In private I told the FM and DFM that I was stepping down for health reasons, but didn't go into detail. Would you? I'm sorry for not being more candid in public at the time."
He said he was making this public now because "I feel we are finally getting to a place where we can talk about this, where we can accept that serious ill-health is something that can affect us all."
And he added: "I went from as low as you can go to accomplishing things that, in my bed that morning in Ninewells Hospital, I never dreamed I'd be able to do.
"Sure, others have done more and still others would do different things. But this has been a life worth living. All lives are."
His tweets prompted a sympathetic response from former SNP colleagues and others at Holyrood.
Mr Swinney told the former MSP: "Didn't think I could have more respect for you than I did before, but I do now. Take care."
Meanwhile, Social Security Secretary Shirley-Anne Somerville said his story was "so powerful".
She told Mr Biagi: "You have achieved so much in and out of politics. But tonight alone you've undoubtedly given hope and strength to many."
Labour health spokeswoman Monica Lennon said: "This is really powerful and courageous. Best wishes to you, Marco."