The court accepted an appeal by Bilin residents, who had argued that the barrier prevented them from reaching 50% of their agricultural land.
Weekly protests against the barrier have been held there for two years.
The Israeli government says the barrier is a security measure but Palestinians view it as an illegal land grab.
The International Court of Justice issued an advisory ruling in 2004 that the barrier breached international law where it is built on occupied territory and should be dismantled.
Correspondents say the latest ruling is an embarrassing blow to the Israeli government at a place which has come to symbolise opposition to the barrier.
"We were not convinced that it is necessary for security-military reasons to retain the current route that passes on Bilin's lands," the chief justice, Dorit Beinish, wrote.
The ruling will prevent a planned expansion of a contentious new settlement project Matityahu East.
Guide: West Bank barrier
The court ruled that the route around Bilin was "highly prejudicial" to the villagers and demanded an alternative route be mapped out "within a reasonable period".
The Bilin protest revolves around 200 hectares (500 acres) of village farmland which the villagers say they have been prevented from using because of the barrier.
Thousands of the village's olive trees have been uprooted as a result of its construction.
One of the Bilin protest organisers, Abdullah Abu Rahma, described the court decision as "wonderful" and called for it to be implemented immediately.
Mustafa Barghouti, an independent member of the Palestinian parliament, told the BBC the ruling was a partial victory.
"It forces the Israelis to move the wall away from Bilin village but it allows for the settlement, which is on Bilin land, to remain," he said.
The Israeli defence ministry, which is responsible for building the barrier, said in a statement it would "study the ruling and respect it".
All Israeli settlements in the West Bank, land captured by Israel in the 1967 war, are deemed illegal under international law, but Israel disputes this.