LONDON — British lawmakers on Thursday voted to postpone the country’s departure from the European Union but, in a rare victory for Prime Minister Theresa May, narrowly failed to wrest control of the Brexit process from her battered government.

After days of turmoil, Mrs. May fended off — by just two votes — a remarkable power grab by lawmakers frustrated at months of political deadlock that has left the country in limbo with just 15 days to go before its scheduled departure from the bloc.

They later voted by 412 to 202 for a motion that means that Britain will almost certainly not leave the European Union as scheduled on March 29, as Mrs. May has repeatedly promised it would.

What remains unclear now is how long the delay will be. Mrs. May plans to hold a third vote on her unpopular plan for withdrawal, despite have suffered two staggering defeats on it already.