The prime minister may have avoided a row with crossbench senator David Leyonhjelm over his bill that would have allowed the Northern Territory and the ACT to set their own policies on assisted dying.
The controversial bill was debated over two days in the Senate but was eventually defeated on Wednesday evening in a 34-36 conscience vote that split Labor and Coalition members.
The result means the bill will not progress to the House of Representatives for a final vote.
Senator Leyonhjelm had threatened to block government legislation in retaliation if Malcolm Turnbull broke an alleged "promise" to allow a free vote. He feared the government would use its one-seat majority to scrap the bill without allowing an open vote.
Mr Turnbull denied any promise existed. Earlier in the week he would only say the government would "consider" a Lower House vote.
The defeat of the bill saves the government a conflict with a Senate crossbencher, but drew strong condemnation from the two territory government involved.
The ACT and Northern Territory, both held by Labor governments, said the removal of the 1997 laws would only give the territories the same rights to govern themselves as the states.
"I want to thank the 34 Senators who stood up for the Australian territories and the communities we represent. It is disappointing that we fell two votes short tonight, but we will not give up," ACT chief minister Andrew Barr said.
"The restoration of Territory rights will be back before the Parliament soon."
NT chief minister Michael Gunner said the 36 senators who voted no had "put territorians last".
"I’m not disappointed, I’m angry," Mr Gunner wrote on Twitter.
Only four Coalition senators voted "yes" to the bill. One was the Queensland backbench senator Ian Macdonald while the other three were prominent frontbenchers: education minister Simon Birmingham, defence minister Marise Payne and indigenous affairs minister Nigel Scullion.
Labor was divided too, with seven of its senators voting "no" and 16 voting "yes".
The Greens and the Centre Alliance senators were all in the "yes" column, as were independents David Leyonhjelm, Derryn Hinch and Tim Storer.
One Nation leader Pauline Hanson voted "yes" but her only remaining colleague Peter Georgiou voted "no", along with conservative independents Fraser Anning, Cory Bernardi and Brian Burston.
Several of Labor's "no" voters were linked to the Shop, Distributive and Allied Employees' Association trade union. Labor senator Pat Dodson also voted no.
Senator Leyonhjelm said public opinion was in favour of legalising voluntary euthanasia.
"The fact we don't have assisted suicide in this country shows a serious flaw in our democracy," he told parliament.
But he praised the tone of the debate, saying it was a demonstration of individual honesty not seen in parliament for some time.
There was a number of emotional reflections, referring to the deaths of terminally ill loved ones.
While some remembered painful farewells and wished assisted suicide had been an option, other senators believed the risks of allowing voluntary euthanasia were too great.
A handful of senators insisted the issue was purely about giving territories the same rights as the states to make laws.
- with AAP