The three-mile long section of the barrier would have taken land from the Palestinian villages of Azun and Nebi Elias. It would also have gone round the illegal Jewish settlement of Tzofim, built on occupied land.
B'Tselem, the Israeli human rights group, said the court had "essentially ruled that the state lied" over claims that the route of the 670km (415 mile) barrier "is based solely on security considerations".
The court gave the state six months to dismantle the section of the barrier and ordered that it be rebuilt along a route which leaves the two villages intact.
Israel says the barrier, which is made up of electric fencing, barbed wire and concrete walls, is to stop potential attackers from infiltrating the country and Jewish settlements.
Palestinians and Israelis have
protested against the barrier
The Palestinians condemn the wall as an attempt to seize their land and undermine the viability of a possible future state.
The UN International Court of Justice issued a non-binding ruling in 2004 that parts of the barrier in the West Bank are illegal and should be removed.
The UN humanitarian affairs co-ordinator's office says three-quarters of the proposed barrier lies in the West Bank, while only 145km follows the Green Line which officially separates Israel and the Palestinian territory.