President Trump had imposed sanctions on Iran last month after pulling out of the nuclear deal involving European allies, a second round of sanctions is due next month.
"The court finds unanimously that... the United States of America... shall remove by means of its choosing any impediments arising from the measures announced on 8 May to the free exportation to Iran of medicines and medical devices, food and agricultural commodities" as well as aeroplane parts, chief judge Abdulqawi Ahmed Yusuf said.
Hailing the verdict of the ICJ, Iran's foreign ministry said it was a "clear sign" that "Iran is in the right".
The ruling by the International Court of Justice "once again shows that the US government... is day by day becoming more isolated," the ministry said in a statement.
The UN's top court gave its judgement after Iran had filed a case against the US for imposing sanctions against it. Iran said the sanctions violated the 1955 Treaty of Amity. The US had argued that Iran was misusing the international court.
Iranian foreign minister Mohammad Javad Zarif had said the sanctions were a form of "psychological warfare" aimed at "regime change".
President Trump after pulling out of the nuclear deal had imposed sanctions on Iran alleging that the Rohani regime was using funds from lifting of sanctions in 2015 to support terrorist activities and to build its nuclear arsenal.
Britain, France and Germany who were co-signatories to the nuclear deal with Iran disagreed with the Trump administration and decided to keep it alive without US support.
The ICJ ruling, however, does not mean it would be enforced as the UN court does not have the power to implement its orders.