LONDON — Prime Minister Theresa May announced her resignation on Friday after three years of trying and failing to pull Britain out of the European Union, throwing her country into an unpredictable situation and setting off a bare-knuckled contest among other Conservative lawmakers to replace her.

As she stood behind a lectern outside 10 Downing Street, Mrs. May admitted that a different leader was needed to shepherd the split, known as Brexit. But she also warned that the unyielding stance taken by the hard-line factions of lawmakers who had proved her undoing would have to change.

“To succeed, he or she will have to find consensus in Parliament where I have not,” Mrs. May said. “Such a consensus can only be reached if those on all sides of the debate are willing to compromise.”