Exclusive

Jeremy Renner was coked up and drunk when he began rhapsodizing about killing his ex-wife Sonni, and the night ended with the actor shoving a gun in his mouth and threatening to kill himself ... so claims Sonni in new legal docs.

Jeremy and Sonni are in a battle royale for custody of their 6-year-old daughter, Ava. She's asking the judge to change the order from joint custody to sole custody on her part with monitored visitation on Jeremy's.

Sonni claims last November Jeremy was at a club, high on coke and booze, when he began talking about killing Sonni, telling someone he "could not deal with her anymore, and he just wanted her gone."

According to the docs, obtained by TMZ, Jeremy put a gun in his mouth, threatened to kill himself, and fired the gun into the ceiling while Ava was asleep in her bedroom.

Sonni claims Jeremy has a history of substance abuse, verbal and emotional abuse. The docs claim Jeremy repeatedly has been under the influence when he had physical custody of Ava. According to the docs, Jeremy once left coke on a bathroom counter which was reachable by Ava.

Sonni alleges in one instance, the nanny overheard Jeremy say he was going to Sonni's house to kill her and then kill himself, because "it was better that Ava had no parents than to have [Sonni] as a mother."

The docs claim Ava told Sonni various women would come and go from Jeremy's house, including "Tayler, Kelley, Natalie, Summer, Faith, Christina, Naz and Jessica."

We reached out to Jeremy's reps ... so far, no word back.