LONDON — For months, Prime Minister Theresa May of Britain has been buffeted between hard-liners who want a clean break with the European Union and those who favor a softer exit to protect the economy. This week she got it from both camps.

On Tuesday, it was the turn of the softer, pro-European conservatives in her ranks who put her to the test, as she narrowly averted defeat in a parliamentary vote that signaled the potential for months of gridlock over the country’s tortured efforts to extract itself from the bloc.

It was the second consecutive day of close votes for Mrs. May, who faced a similar challenge on Monday from hard-liners, a measure of the tightening course she must navigate between the competing camps within her Conservative Party.

Mrs. May secured victory by just six votes on Tuesday, scraping home in the highly charged aftermath of two cabinet resignations and amid persistent speculation about a challenge to her leadership.