LONDON  Prime Minister Gordon Brown faced down a revolt within his governing Labor Party on Wednesday, winning a precariously narrow victory in the House of Commons for a measure that among other things would allow the authorities to hold terrorism suspects for up to 42 days without charges.

Whether the measure becomes law, and when, now depends on the government’s success in navigating the new counterterrorism bill past the House of Lords, where it may not be introduced until the fall and where it is expected to meet stronger opposition.

Opponents of the measure, which extends the current detention limit of 28 days, say it would give Britain detention powers that have few parallels in other Western democracies. They have promised a legal challenge under the European Convention on Human Rights, a recourse that has led to increasingly frequent rebuffs for the British government on issues affecting civil liberties.

The House of Commons vote was 315 to 306, with the nine-vote margin supplied by a last-minute decision to vote for the measure by the Democratic Unionist Party, a group of Northern Ireland Protestants who share power in the Belfast government with the predominantly Roman Catholic Sinn Fein. More than 30 Labor rebels who voted against the measure appeared to have stood firm in their opposition despite intense pressure from Mr. Brown, whose determination to press ahead with the bill had turned the vote into a test of his own embattled leadership.