A US resolution championed by Ambassador Nikki Haley to condemn the Palestinian Hamas movement at the United Nations for firing rockets at Israel failed to win enough votes for adoption on Thursday.
The proposed measure won 87 votes in the General Assembly, falling short of the required two-thirds majority.
Fifty-eight countries opposed the measure and 32 abstained.
Haley, who steps down from her post at the end of the year, has repeatedly accused the United Nations of having an anti-Israel bias and has defended Israel in its latest confrontation with Hamas, the Islamist militant group that has ruled the Gaza Strip since 2007.
It was the first proposed resolution condemning Hamas to be presented to the 193-nation assembly, which has been meeting since 1946.
Speaking ahead of the vote, Haley said the measure "would right a historic wrong" and "put the General Assembly on the side of truth and balance in the effort to achieve peace in the Middle East."
"The question before us now is whether the UN thinks terrorism is acceptable if, and only if, it is directed against Israel," she told the assembly.
Hamas praised the outcome of the vote, describing it as a "slap" to President Donald Trump's administration which has taken a firm pro-Israeli stance in addressing the Middle East peace process.
"The failure of the American venture at the United Nations represents a slap to the US administration and confirmation of the legitimacy of the resistance," Hamas spokesman Sami Abu Zahri wrote on Twitter, using a phrase commonly used to refer to armed groups that oppose Israel.
Israeli Ambassador Danny Danon lamented after the vote that a decision to condemn Hamas had been "hijacked" by procedural votes and hailed the "broad support from the world" for condemning Hamas.
Kuwait had asked the assembly, on behalf of Arab countries, to require a two-thirds majority, which was narrowly endorsed by a vote of 75 in favour, including EU countries, 72 against and 26 abstentions.
The United States had won crucial backing from the European Union, with all 28 countries supporting the US measure that would have condemned Hamas for firing rockets into Israel and demanded an end to the violence.
The European Union, like the United States, considers Hamas a terror group.
The assembly also adopted by a wide margin of 156 to six with 12 abstentions a Palestinian-drafted measure, presented by Ireland, calling "for the achievement, without delay, of a comprehensive, just and lasting peace in the Middle East" based on UN resolutions.
The United States, Israel, Australia, Liberia, Marshall Islands and Nauru voted against that measure.
The vote at the assembly took place as Haley prepares to step away from public life even as polls show she remains one of the most popular members of Trump's cabinet.
Haley rattled the United Nations when she arrived in January 2017 vowing that the United States will be "taking names" of countries that oppose Trump's foreign policy.
Ahead of the vote, the US ambassador sent a letter to all UN missions to make clear that "the United States takes the outcome of this vote very seriously."
"She would like to go out with something," said a Security Council diplomat of the US-drafted resolution.
Resolutions adopted by the General Assembly are non-binding, but they carry political weight and are seen as a barometer of world opinion.
The US defeat at the General Assembly came as the Trump administration prepares to unveil long-awaited peace proposals, possibly in the first months of next year.
The Palestinians have severed ties with the Trump administration since the decision a year ago to move the US embassy to Jerusalem and declare the city Israel's capital.
The Palestinians see East Jerusalem as the capital of their future state. International consensus has been that Jerusalem's status must be negotiated between the two sides.