The non-binding resolution was approved at a UN General Assembly emergency meeting on Thursday with 128 votes in favour and nine against, while 35 countries abstained.
It passed despite intimidation by Trump, who had threatened on Wednesday to eliminate financial aid to member states who would vote against his decision, while Nikki Haley, the US ambassador to the UN, had warned that she would be "taking names" of those countries.
Shortly after the vote, Palestinian leaders called the vote a victory for Palestine and thanked the UN member states that rejected Trump's unilateral move "despite all the pressure exerted on them".
"This decision reaffirms once again that the just Palestinian cause enjoys the support of international community, and no decisions made by any side could change the reality, that Jerusalem is an occupied territory under international law," Nabil Abu Rudeina, spokesman for Palestinian President Mahmoud Abbas, said in a statement.
Saeb Erekat, the Palestinian chief negotiator, condemned Washington's decision but said the UN vote showed respect for the rule of law.
"It's a day of shame to those who stood shoulder to shoulder with the occupation and settlements against international law," he said.
"But we appreciate very much that the majority of the international community decided, in spite of the threats and intimidation of the US, to stand tall with wisdom, far-sightedness, international law and the rule of law - and not the rule of the jungle."
Mevlut Cavusoglu, foreign minister of Turkey, a co-sponsor of the resolution, said on Twitter that "dignity and sovereignty are not for sale".
Mohammad Javad Zarif, Iran's foreign minister, also welcomed the result of the vote on Twitter, calling it "a resounding global NO to Trump regime's thuggish intimidation" at the UN.
For his part, Israel's Prime Minister Benjamin Netanyahu, who had earlier called the UN a "house of lies", condemned the "preposterous" vote and thanked Trump for his stance on Jerusalem.
"I do appreciate the fact that a growing number of countries refused to participate in this theatre of the absurd," he said in a televised statement.
"So I appreciate that, and especially I want to again express our thanks to President Trump and Ambassador Haley, for their stalwart defence of Israel and their stalwart defence of the truth."
The session on Thursday at the 193-member body was held at the request of Arab and Muslim countries after the US vetoed the same measure in the Security Council on Monday.
The US was outnumbered 14 to 1 in that vote.
While the Security Council's five permanent members - the US, Britain, France, China and Russia - had veto power on Monday's vote, there are no vetoes at the General Assembly.
Similar to the Egyptian-drafted text that was blocked by Washington on Monday, the draft resolution approved on Thursday did not mention the US by name but expressed "deep regret at recent decisions" concerning Jerusalem's status.
Marwan Bishara, Al Jazeera's senior political analyst, called the result of the General Assembly vote a "great humiliation for the US".
Bishara said that most UN member states that voted in favour of the draft resolution did not necessarily do so to back the Palestinians but to support "international legality".
"They voted for what they saw as a violation of international law," he said.
"The resolution starts by naming several UN Security Council resolutions, where the US either voted for or abstained, saying that Israel cannot annex East Jerusalem; that Israel cannot export its own population to East Jerusalem; that Israel cannot continue with the settlement building in East Jerusalem and so on," added Bishara.
"All in all, 128 countries voted for international law."
In addition to recognising Jerusalem as Israel's capital, Trump announced on December 6 that the US would move its embassy from Tel Aviv to Jerusalem.
No country currently has its embassy in the city, which is home to holy religious sites and has particular significance for Muslims, Christians and Jews.
The US decision triggered a series of protests in the occupied Palestinian territories, as well as major international cities - from Jakarta, through Istanbul, to Rabat.
The status of Jerusalem has long remained a sensitive topic and one of the core issues in the Israeli-Palestine conflict.
After occupying the city's eastern part in the 1967 War, Israel annexed the territory. In 1980, it proclaimed it as its "eternal, undivided capital."
They have warned that any change to the status quo would mean the end of the peace process premised on a two-state solution.
Thursday's vote was reminiscent of a session in 2012, when an overwhelming majority backed Palestine's upgrade in the UN to non-member state status.
In that vote, some 138 countries supported the upgrade, while nine - including the US, Israel, Canada and several South Pacific countries - voted against.