Although the rulings of the International Court of Justice (ICJ) are binding, it has no direct means of enforcing them, and in rare cases in the past countries have ignored them.
"The Russian Federation shall immediately suspend the military operations that it commenced on Feb 24, 2022 on the territory of Ukraine," the ICJ judges said in a 13-2 decision.
They added that Russia must also ensure that other forces under its control or supported by Moscow should not continue the military operation.
Ukraine filed its case at the ICJ shortly after Russia's invasion began on Feb. 24, saying that Moscow's stated justification, that it was acting to prevent a genocide in eastern Ukraine, was unfounded.
In addition to disputing the grounds for the invasion, Kyiv also asked for emergency "provisional" measures against Russia to halt the violence before the case was heard in full. Those measures were granted on Wednesday.
During hearings earlier this month, Ukraine said there was no threat of genocide in eastern Ukraine, and that the U.N.'s 1948 Genocide Convention, which both countries have signed, does not allow an invasion to prevent one.
Ukrainian government forces have been battling Russia-backed separatists in the Donbass region of eastern Ukraine since 2014.
Kyiv and its Western allies reject Moscow's claims of any genocide being perpetrated against Russian speakers there.
Russia said it had skipped the hearings at the ICJ, also known as the World Court, "in light of the apparent absurdity of the lawsuit". It later filed a written document arguing that the court should not impose any measures.
Ukrainian President Volodymyr Zelenskiy on Wednesday welcomed the ruling by the ICJ on emergency mesaures as "a complete victory" in its case against Russia.
"The (ICJ) order is binding under international law. Russia must comply immediately. Ignoring the order will isolate Russia even further," Zelenskiy said on Twitter.
Reading out Wednesday's ruling, presiding judge Joan Donoghue said the court was "profoundly concerned about the use of force by the Russian Federation in Ukraine which raises very serious issues of international law".
(Reporting by Stephanie van den Berg, Marine Strauss, Natalia Zinets and Max Hunder; Writing by Anthony Deutsch; Editing by Michael Perry, Jonathan Oatis and Gareth Jones)