JERUSALEM — Prime Minister Benjamin Netanyahu of Israel seemed headed for a showdown with hard-core Jewish settlers on Wednesday, after his ministers followed his instructions to vote against a draft bill that would have retroactively legalized illegally built settler homes in the West Bank.

The bill was defeated 69 to 22 in the 120-seat Parliament, paving the way for the imminent removal of five apartment buildings housing about 30 families that were built on privately owned Palestinian land in an extension of an existing settlement. Israel’s Supreme Court has ordered the state to demolish the buildings by July 1. In the end, Mr. Netanyahu faced down the more right-wing elements within his government coalition and his own Likud Party, prevailing after intense discussions in the past few days and pledging to build housing for 300 families in the settlement itself, Beit El.

This was Mr. Netanyahu’s first major move on the contentious settlement issue since he expanded his power by bringing the centrist Kadima Party into his coalition last month, giving his government a mammoth 94-seat majority in Parliament.

Settlement construction has been an acute source of friction for the Israeli government, the Obama administration and other international powers. Rejection of the outpost bill averted entanglement with the Supreme Court and the international condemnation the bill would inevitably have stirred.