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
- STV poll: 53% of Scots would vote for independence if ballot held now
- Teenager stole saltire flags and referendum placard from gardens
- Scots would vote Yes if referendum was held now, according to poll
- New voter registration system must be 'carefully implemented'
- Alex Salmond hints at second referendum if devolution 'Vow' not kept
- Lord Smith warns parties against backsliding on more powers
- Referendum uncertainty led to housing market drop, says survey