First Minister Alex Salmond and defence spokesman Angus Robertson were left relieved following the narrow victory, with their new defence policy approved by just 29 votes.
The decision will leave an independent Scotland free to join Nato despite the party's long-standing opposition to nuclear weapons.
Loading article content
"Who dares, wins," Mr Robertson said after the closer-than-expected vote, which resulted in the architect of the major shift being booed at the Perth conference during a fierce two-hour debate.
However, despite 365 delegates going against the party leadership over membership of the pro-nuclear weapons organisation, dissenters have pledged to move on from the issue, respect the result and concentrate on the road to the 2014 referendum.
Alex Salmond and his deputy, Nicola Sturgeon, were on the platform for the debate, brandishing delegate cards above their heads as part of the vote that saw a critical amendment defeated 394-365.
But from the floor it was Justice Secretary Kenny MacAskill who helped sway the result, with his intervention coming after MSP Sandra White received the strongest cheers for claiming it was "hypocritical" to advocate joining a pro-nuclear club when the party wished to rid the country of nuclear weapons.
She criticised Mr Robertson's polling evidence that most Scots would prefer to remain in Nato, saying: "I speak to the grassroots of this party and they don't want nuclear weapons and they don't want membership of Nato either."
Mr Robertson had argued it was right that the party, for the first time in a decade, should consider "updating" its policies to take account of the views and role of Scotland's Nato allies such as Denmark and Norway.
Future Scottish membership of Nato was described as "totally conditional" on the removal of nuclear weapons from Faslane, which would become a conventional naval base.
Jamie Hepburn, MSP for Cumbernauld and Kilsyth, moved the key amendment seeking to retain SNP policy that an independent Scotland would leave Nato and instead join the more loosely affiliated Partnership for Peace grouping.
He said: "If you take as your starting point remaining in Nato we can expect it to be harder to remove Trident from the Clyde. Where is the morality in remaining under the umbrella of an alliance with a first-strike nuclear policy?"
Veterans Minister Keith Brown said he had made the transition from being a member of the Marines who had fought in the Falklands to joining the SNP and embracing its anti-nuclear stance. Now he believed the updated defence policy was the right way forward.
But his partner, Christina McKelvie, MSP for Hamilton, Larkhall and Stonehouse, argued strongly against the new policy, citing atrocities around the world perpetrated by Nato including drone attacks killing children in Pakistan. In foreign policy terms, she said: "I don't want to be a paler shade of UK policy."
Finance Secretary John Swinney swung support behind the new defence policy, as did former Cabinet Secretary and party favourite Bruce Crawford. This was despite a summing-up that saw Mr Robertson again on the back foot – with boos when he again cited polling evidence showing Scots in favour of Nato membership. He said it was the public that had to be swayed, not the party faithful.
Labour's Paul Martin said: "The SNP leadership can take no credit from this debate when their defence spokesman admits to members this is not about principle, it is about making independence more acceptable to the majority of Scots who disagree with them.
"After compromising on the Queen, on currency, on finan-cial regulation and now Nato, people will be wondering which one of the Nationalists' values Alex Salmond is going to ditch next."
Ms McKelvie later said the vote would be respected and that no further action was expected from opponents to Nato membership. She added: "Democracy was the winner today. Now we can put this behind us and focus on winning Yes votes."
John Ainslie of Scottish CND described the result as a pyrrhic victory for Alex Salmond. He said: "The leadership of the SNP were only able to push through this change in policy by putting pressure on elected members, ministers and delegates.
"The impassioned speeches against Nato showed that many in the party recognise the hypocrisy of banning Trident from the Clyde and joining a nuclear alliance. It will be very difficult for the SNP to persuade their activists to sell this pro-Nato message on the streets during the referendum campaign."