The vote late Tuesday was 144 in favor, 4 opposed and 12 abstentions.
Agreement on the final text was reached after extraordinary public negotiations on the final text between the European Union and the Palestinians and Arab and Islamic nations.
The United States, which vetoed a Security Council resolution last week that would have declared the barrier illegal, voted against the General Assembly resolution. There are no vetoes in the 191-member world body and its resolutions are not legally binding, but they are considered a reflection of international opinion.
In return for EU support, the Palestinians and other Arab and Islamic nations agreed to drop a second resolution that would have asked the International Court of Justice at The Hague, Netherlands, for an advisory opinion on the legality of the barrier.
To get the 15 EU nations to support the resolution, the Palestinians and their supporters agreed to eliminate a statement calling the barrier "illegal" and add a condemnation of Palestinian suicide bombings, so-called "extrajudicial killings" by the Israelis, and the recent bomb attack in the Gaza Strip which killed three American security officers.
The resolution "demands that Israel stop and reverse the construction of the wall in the occupied Palestinian territory, including in and around East Jerusalem, which is in departure of the Armistice Line of 1949 and is in contradiction to relevant provisions of international law."
It asks Secretary-General Kofi Annan to report on compliance periodically, with the first report to be submitted within one month. Once the report is received, it says, "further actions should be considered, if necessary, within the United Nations system."
Palestinians say the barrier--a network of fences, walls, razor wire and trenches stretching 90-plus miles--is a land grab ahead of any possible talks about the borders of a Palestinian state.
Israel insists the barrier is essential to prevent suicide attacks against Israelis and that its construction is purely for security and will help create an atmosphere conducive to peace talks.
Many EU members didn't want the world court involved, and neither did the United States.
The final round of negotiations dragged on for more than six hours after the vote was scheduled Tuesday afternoon, and moved into the corridor outside the General Assembly hall for several hours. There, EU ambassadors huddled in one area and Arab and Islamic ambassadors in another, with dozens of other envoys who had come to vote hanging on the fringes trying to find out what was going on.
Italy's U.N. Ambassador Marcello Spatafora, whose country holds the EU presidency, moved between the two groups, sometimes with the British or French ambassadors alongside, conducting often heated negotiations with the Palestinian U.N. observer Nasser Al-Kidwa.
"This is really balanced," Spatafora insisted at one point, waving his hands in the air in front of Al-Kidwa. "This is not only about the wall. It's about trying to get both parties to fulfill their obligations."
The resolution calls on both the Israelis and Palestinians to fulfill their obligations under the "road map" peace plan drafted by the EU, the United Nations, the United States and Russia.
Specifically, it says the Palestinians should "undertake visible efforts on the ground to arrest, disrupt, and restrain individuals and groups conducting and planning violent attacks." It says Israel should "take no actions undermining trust, including deportations and attacks on civilians and extrajudicial killings."
In an organization where negotiations almost always are conducted behind closed doors, the public negotiations were a rare public display of efforts to get broader support for a resolution.
At one point, Germany's U.N. Ambassador Gunter Pleuger said: "The negotiations on the last three words are always most difficult." Sweden's U.N. Ambassador Pierre Schori added: "We are close — close to a breakthrough, close to collapse."
The Palestinians went to the General Assembly after the United States vetoed a Security Council resolution last week that would declare that the construction of a barrier was illegal and call for it to be dismantled. It sought a similar resolution from the General Assembly.
Despite the improvements in the final EU-backed draft, U.S. deputy ambassador James Cunningham said the United States wouldn't support it because it doesn't name Palestinian terrorist groups carrying out suicide bombings in Israel — such as Hamas and Islamic Jihad.
"Although it doesn't say illegal any more, it still passes judgments on compliance with legal standards that we don't think is appropriate in this case — even though we have concerns about the process that's going on with the fence," he said.