Media playback is unsupported on your device Media caption The government has dodged a defeat on its key Brexit legislation

The government has avoided a major defeat on its Brexit bill by 324 votes to 298 after a late concession.

Ministers saw off a move to give MPs the decisive say on what happens over Brexit if they do not agree with the deal negotiated by the UK government.

Following a meeting with Theresa May, Tory MPs said they had been promised "input" into what the government would do if the UK faced a no-deal scenario.

But one minister told the BBC he would commit only to "further discussions".

Solicitor General Robert Buckland said the government remained "open-minded", but this may or may not result in it coming forward with new proposals in the coming days.

The BBC's political editor Laura Kuenssberg said she had been told by a government source that no actual concessions had been agreed and the only agreement was to keep talking.

Tuesday's Commons debate marked the start of the government's attempts to undo most of the changes to its EU Withdrawal Bill that were put forward by the House of Lords.

Media playback is unsupported on your device Media caption Solicitor General, Robert Buckland says Brexit legislation will be improved

The most contentious was the bid to give Parliament the power to tell the government what to do if the Brexit deal was voted down or no agreement was reached.

While in the end, only two Tory MPs - Ken Clarke and Anna Soubry - voted against the government, there were clashes over how much of a say Parliament should get as the UK leaves the EU, with one side accusing the other of trying to "wreck" Brexit - and being accused in turn of being "zealots" who wanted to sideline Parliament.

Seeking to placate would-be Conservative rebels, government frontbenchers offered to meet them to discuss their concerns, and agreed to "engage positively" on a "compromise" put forward by one of them, former attorney general Dominic Grieve.

Details of precisely what this will involve will be agreed in the coming days when the bill is due to return to the House of Lords and ministers could table a fresh amendment.

The government blinked first

Image copyright AFP

Analysis by BBC Parliamentary correspondent Mark D'Arcy

The government would not have sought a deal if it thought it had the votes to win, and they clearly blinked.

The decision to seek a compromise marked an important victory for the soft Brexit/Remainer/"realist" Tory rebels, who have been promised an amendment giving them most of what they want.

Read Mark's full blog

Mr Grieve said he had "confidence and trust" in Theresa May to address the concerns of more than a dozen MPs who are reported to have held last-minute talks with the prime minister in her Commons office during the debate.

He said if the UK and EU were unable to agree a deal in the autumn, or if MPs rejected the deal on offer as inadequate, there would be a "national crisis", with the real prospect of the UK leaving in March 2019 without an agreement.

Media playback is unsupported on your device Media caption Sir Edward Leigh urges MPs not to "stand in the way of the people"

Media playback is unsupported on your device Media caption Stand up for what you believe in - Anna Soubry says

In such a situation, he said, Parliament should be able to flex its muscles by requiring ministers to come forward with a plan of action, which MPs would be able to debate and vote on.

Several Tory MPs, including Heidi Allen, have suggested ministers have accepted this.

But the government is not believed to be willing to agree to Mr Grieve's call for MPs to effectively take control of negotiations in the last resort if no deal is agreed by February 2019.

Jacob Rees-Mogg, chair of the influential European Research Group of MPs, told the BBC a concession of this kind would have been "revolutionary" as the Commons could not override the government when it came to negotiating international treaties.

The leading Brexiteer said Mrs May had "paid attention to both sides" and the unity displayed by his party would strengthen the PM's hand in negotiations in the run-up to June's EU leaders' summit.

Fellow Brexiteer Sir Bill Cash said he was pleased the Lords amendment, which he said would have given Parliament an effective veto over Brexit, had been "soundly and significantly defeated".

'Held to account'

Labour, five of whose MPs defied the leadership by voting with the government, said the prime minister may have avoided a "humiliating defeat" but the fight to ensure Parliament had a "proper role" in shaping the outcome of negotiations would continue.

"We will wait and see the details of this concession and will hold ministers to account to ensure it lives up to the promises they have made to Parliament," said the party's Brexit spokesman Sir Keir Starmer.

Earlier, the government suffered its first ministerial resignation over Brexit as Phillip Lee quit the Ministry of Justice so he could speak out freely.

Image copyright House of Commons Image caption Phillip Lee spoke from the backbenches after quitting his ministerial job

Mr Lee said Parliament was being sidelined, and called for another referendum to be held when the final direction of Brexit became clear.

Revealing he had abstained in the Commons vote on Parliament's role, he said he was "delighted" at the government's concession, adding: "This justifies my decision to resign and makes it a lot less painful."

The government, meanwhile, has reversed a series of other changes made by the Lords to the EU Withdrawal Bill, including reinstating the precise day of departure - 29 March 2019 - in the proposed legislation.

A government amendment on the Irish border, guaranteeing there will be no new border arrangements without the agreement of the UK and Irish authorities, was also approved by MPs.