Chester Bennington's autopsy shows he had a trace amount of alcohol in his system when he hanged himself ... TMZ has learned.

According to the autopsy and toxicology results, obtained by TMZ, the Linkin Park singer's blood also tested "presumptive positive" for MDMA (ecstasy) ... based on one test. Two subsequent tests did not detect the drug, and the ultimate conclusion was Chester was not under the influence of drugs when he died.

Authorities found a prescription bottle of Zolpidem -- generic Ambien -- on his dresser. There was also a pint glass of Corona, which was less than half full -- and an empty bottle of Stella Artois.

Police found pieces of fingernail underneath his iPhone and on a table in the bedroom. Chester's wife, Talinda, told cops he would do that when he was anxious. She said Chester had a history of depression and previous suicide attempts -- including one in 2006 when he left the house with a gun after drinking heavily.

Talinda added Chester was currently in an outpatient treatment program. A month before his death, Chester reportedly told friends he'd been sober for 6 months.

He'd been prescribed anti-depressants in the past, but had not taken them for more than a year ... according to Talinda.

TMZ broke the story ... Chester committed suicide July 20 by hanging himself. The report says he was found with a black Hugo Boss leather belt around his neck. He still had the boarding pass in his pocket from the flight he'd taken from Phoenix the day before his death.

There was no suicide note, but police found what they call an "apparent biography," which was handwritten.