Before the vote on the resolution, the 193-member world body had narrowly voted to require a two-thirds majority for approval as sought by Arab nations for rather than the simple majority urged by the United States.
U.S. Ambassador Nikki Haley told the assembly before the vote that it could make history and unconditionally speak out against Hamas, which she called "one of the most obvious and grotesque cases of terrorism in the world."
"What the U.N. chooses to do today will speak volumes about each country's seriousness when it comes to condemning anti-Semitism," she said. "Because there is nothing more anti-Semitic than saying terrorism is not terrorism when it's used against the Jewish people and the Jewish state."
But the vote on the resolution to condemn Hamas was 87 in favor against 57 opposed, with 33 abstentions - a plurality but below the two-thirds requirement to adopt it. The vote to require a two-thirds majority was much closer, 75-72, with 26 abstentions and several countries changing their votes to "yes" at the last minute.
In an official statement, Hamas thanked U.N. member states "that stood by our people's resistance and the justice of their cause" and attacked Haley who it said "is known for her extremism and her positions that support the Zionist terrorism in Palestine."
Palestinian President Mahmoud Abbas, whose Fatah party is locked in a bitter decade-long split with Hamas, also welcomed the resolution's defeat saying: "The Palestinian presidency will not allow for the condemnation of the national Palestinian struggle."
By contrast, Israel's Prime Minister Benjamin Netanyahu praised the "large majority" - 87 countries - "that took a stance against Hamas" for the first time, calling it "an important achievement for the United States and Israel."
The U.S. attempt to condemn Hamas and demand that the militant group stop firing rockets into Israel, using "airborne incendiary devices" and putting civilians at risk sparked a Palestinian-backed amendment sponsored by Bolivia.
It outlined the basis for comprehensive Israeli-Palestinian peace and referred to a December 2016 Security Council resolution that condemned Israeli settlements in the West Bank and east Jerusalem as a "flagrant violation" of international law. It also reaffirmed "unwavering support" for a two-state solution to the Israeli-Palestinian conflict - issues not included in the U.S. draft.
But before the vote on the U.S. draft resolution, Bolivian Ambassador Sasha Llorentty Soliz withdrew the amendment.
That was because the Palestinians and their supporters wanted a vote instead on a short rival resolution entitled "Comprehensive, just and lasting peace in the Middle East" sponsored by Ireland that included the exact language of the amendment - but no mention of Hamas.
After the U.S. draft on Hamas failed to win adoption, the General Assembly overwhelmingly approved the Irish resolution by a vote of 156-6, with 12 abstentions.
It calls for "the achievement, without delay" of lasting Mideast peace on the basis of U.N. resolutions, singling out the December 2016 measure. And it reaffirms "unwavering support ... for the two-state solution of Israel and Palestine, living side by side in peace and security within recognized borders, based on the pre-1967 borders."
The rival resolutions reflect the deep divisions among the 193 U.N. member states over the decades-old Israeli-Palestinian conflict - and the failure to end it.
Saudi Arabia's U.N. Ambassador Abdallah Al-Mouallimi, reflecting the Arab view, said the U.S. resolution would "undermine the two-state solution which we aspire to." And he said it would also turn attention away from Israel's occupation, settlement activities and "blockade" - whether in Gaza, the West Bank or east Jerusalem which the Palestinians want as their future capital.
Haley sharply criticized the United Nations as having an anti-Israel bias, noting that "over the years, the U.N. has voted to condemn Israel over 500 times" - an average of 20 times a year.
She stressed that Hamas' charter "openly calls for the destruction of Israel" and cited a variety of "barbaric terrorist tactics" it has used including suicide bombers and thousands of rockets, flaming kites and balloons.
Haley called condemnation of Hamas "an essential step" to a peace settlement.
The United States changed its initial draft resolution to get backing from the 28-nation European Union, adding that it supports a comprehensive peace agreement "bearing in mind relevant United Nations resolutions."
But the resolution that was voted on never mentioned a two-state solution or referred to Israeli actions against the Palestinians, which some countries considered unbalanced.
The overwhelming support for the Irish resolution reflects global support for action "without delay" toward an end to the Israeli-Palestinian conflict and a two-state solution.
Associated Press writers Fares Akram in Gaza City, Gaza Strip, and Josef Federman in Jerusalem contributed to this report.
Copyright 2018 The Associated Press. All rights reserved. This material may not be published, broadcast, rewritten or redistributed.