Delegates at the SNP autumn conference in Perth have narrowly backed taking an independent Scotland into Nato on the condition that it would be able to remove its nuclear weapons.
An amendment to reaffirm the party's traditional anti-Nato stance was rejected by 394 votes to 365 after a card count late on Friday afternoon. A further vote to remit the Nato U-turn back to SNP policymakers for further consideration was also narrowly voted down by 425 to 360.
Party rebels led by MSP Jamie Hepburn and seven other MSPs tried to quash the U-turn and reaffirm the party's support for non-Nato alliance Partnership for Peace, but their efforts were in vain.
The decision means that the SNP will now apply to keep Scotland in Nato if it is elected to lead the first post-independence government.
Delegates backed party leadership and defence spokesman Angus Robertson, who had warned that withdrawing Scotland from Nato would be like "pulling the plug on the radar" protecting the North Sea.
He said: "Everything that is around Scotland turns into a black hole where we have no idea what's going on, and that worries our neighbours intensely."
But he suggested he would take the risk if Nato insisted that Scotland must keep its nuclear weapons.
Mr Robertson continued: "Politics and risk go hand in hand. Sometimes you just need to stand up and say this is something we need to advance and this is something we need to deal with."
Patrick Harvie, MSP for Glasgow and Co-convener of the Scottish Greens, called the decision "moral hypocrisy of the worst kind".
He said: "Rather than building a platform of distinctive policies that make the case for a radically better Scotland, the SNP leadership seem determined to quash the party's better instincts.
"It is moral hypocrisy of the worst kind to be so vocal in opposition to Trident but in favour of an alliance based on the nuclear protection of other states. This is a profound misjudgement that sets the face of the SNP against radical Scotland at a time when they should be energising campaigners."
The SNP had opposed Nato for decades, previously arguing that it is a nuclear alliance at odds with the party's anti-nuclear stance.
Some defence experts and officials from the Ministry of Defence and the Foreign Office have warned that Nato membership cannot be taken for granted, suggesting that the Nato top brass may take exception to the SNP's anti-nuclear stance.
Before the vote, a former Nato secretary-general warned that an independent Scotland's membership of the organisation would be "uncertain at best".
Lord Robertson of Port Ellen questioned whether membership of Nato would even be open to Scotland under the terms of the SNP's new policy.
More About Referendum
- Scotland's European Union membership 'not in doubt' claims study
- Indyref Daily: Are we ready to cut Auntie out of the family?
- Post-independence break up of BBC would be 'devastating' says Curran
- Indyref Daily: Appeal of radical ideas shouldn't be dismissed
- Fresh call for First Minister to reveal his currency 'plan B'
- Tourists would visit Scotland 'regardless of referendum outcome'
- Indyref cheat sheet: Defence, security and the nuclear deterrent