"We want negotiations to start unconditionally and I am happy that all sides have agreed to do that," Zalmay Khalilzad, the US ambassador, said, though he said the parties had accepted the resolution "reluctantly".
Western Sahara, larger than Britain but with a population of just 260,000, has lucrative phosphate reserves, rich fishing grounds and potentially oil.
Many thousands of its people live in refugee camps across the border in Algeria.
The council's move followed the submission to the UN by both Morocco and the Algeria-based Polisario of rival plans for the future of the former Spanish colony, annexed by Morocco after Madrid pulled out in 1975.
|Western Sahara is sparsely populated but rich|
in phosphate reserves and fishing grounds
Morocco wants talks about self-rule for the territory under Moroccan sovereignty, but Polisario has demanded a referendum that would include the option of full independence.
The resolution "calls upon the parties to enter into negotiations without preconditions in good faith ... with a view to achieving a just, lasting and mutually acceptable political solution, which will provide for the self-determination of the people of Western Sahara".
It requested Ban Ki-moon, the UN secretary-general, to set up the negotiations under his auspices and provide a report by June 30 on how they were progressing.
Friends of Rabat
One factor in its shift appeared to be pressure in Morocco's favour from Washington, concerned that the dispute was hampering the fight against Muslim fighters in North Africa.
Rabat has also been backed by traditional ally France.
Jean-Marc de la Sabliere, the French ambassador to the UN, praised Morocco for "creating a new dynamic".
Polisario was supported in the Security Council by South Africa, which said it was shelving its concerns over the resolution to get the talks started.
Morocco, which saw a vigorous campaign in Washington rewarded with a UN text that seemed warmer to its proposals than to Polisario's, hailed the outcome.
Taieb Fassi Fihri, Morocco's deputy foreign minister, said in Rabat: "It is ... a substantive resolution that establishes a decisive turning point in the search for a realistic and realisable solution of the issue."
Polisario officials also claimed victory despite describing the resolution as unbalanced.
The text hails Morocco's "serious and credible" efforts to end the long crisis while merely "taking note of" Polisario's proposals.
Mhamed Khadad, a senior official, said: "The Sahrawi people have thus achieved that their right to self-determination, which ... Morocco and its allies have done everything possible to deny them, has been placed at the heart of any solution."
Each side, however, defines self-determination in its own way.
Rabat says letting Sahrawis vote on the result of autonomy talks would cover it.
Polisario wants a referendum offering a choice of independence, autonomy or integration into Morocco.
A UN ceasefire agreement in 1991 promised a referendum, but it never took place.
It was not immediately clear how or when Ban would seek to convene the talks.
Until now, the Security Council had not called for direct talks.