South Africa brought the case to the International Court of Justice (ICJ) earlier this month, asking it to grant emergency measures to halt the fighting, which has killed more than 26,000 Palestinians.
It accused Israel of state-led genocide in its offensive, begun after Hamas militants stormed into Israel killing 1200 and kidnapping more than 240. Israel sought to have the case thrown out.
Israel's bombardment of Gaza has laid waste to much of the enclave. (EPA PHOTO)
In Friday's ruling, the judges said Israel must take all measures within its power to prevent its troops from committing genocide and must take steps to improve the humanitarian situation.
The ICJ did not rule on the core of the case brought by South Africa - whether genocide has occurred in Gaza. But it recognised the right of Palestinians in Gaza to be protected from acts of genocide.
It said it would not throw out the genocide case, ruling that the Palestinians appeared to be a protected group under the 1948 Genocide Convention.
It stopped short of ordering a ceasefire.
South Africa had requested an immediate halt to Israel's military operation, arguing two weeks ago that Israel's aerial and ground offensive was aimed to bring about "the destruction of the population" of Gaza.
Israel has called South Africa's allegations false and "grossly distorted", and said it makes the utmost efforts to avoid civilian casualties.