The government has caved in to pressure over the fate of EU citizens in the event of a no-deal Brexit and agreed to go back to Brussels to seek a deal to ringfence their rights.

Its decision follows a morning of chaos during whichthe Conservative MP who tabled the amendment proposing the move was forced to quit his government post, and the home secretary said he saw “nothing wrong” with the plan even though Theresa May had dismissed it a day earlier.

Just hours after Alberto Costa resigned, the Cabinet Office minister David Lidington told MPs the government supported him and would take his plan up with the EU. “In view of the fact our political objectives are the same, the government will accept the amendment today and take it up with the commission,” he said.

The amendment calls on May to seek “at the earliest opportunity a joint UK-EU commitment to adopt” the part of the withdrawal agreement securing the rights of EU citizens in the UK and British nationals settled in the EU, whatever the outcome of Brexit negotiations.

While Lidington said the government took the rights of EU citizens including British nationals settled in the bloc “extremely seriously”, he warned that MPs should not “underestimate the challenge” in persuading the EU.

The events leading up to the statement were branded a “shambles” by the shadow Brexit secretary, Keir Starmer, following a clash between MPs and the home secretary over the amendment.

Sajid Javid appeared blindsided when he told MPs on a select committee that there was nothing wrong with the amendment only to be told the government had indicated it would not be backing it. “When did you hear that? From who?” he asked them.

When told it had been the prime minister, Javid replied: “Did you? Right, ok”, before adding: “I’m perfectly happy with that amendment.”

There was further confusion when an hour later, Costa left his post as parliamentary private secretary to the Scotland secretary, David Mundell.

Sources close to Costa said he was given no option but to resign, after tabling the amendment. A source said: “It seems ridiculous for the government to be sacking a parliamentary private secretary over an amendment that has cross–party support and the support of upwards of 60 Tory backbenchers and Sajid Javid.”

Starmer told the house the chaos was a “vignette on how Brexit has been going”.

A Downing Street spokesman said Costa had not been sacked. “He resigned from the government,” he said. “You will be aware that there is a longstanding convention that members of the government payroll, including PPSs, don’t table amendments to government bills. Clearly this is an issue that he feels very strongly about and so he has chosen to resign.”

He said it was “absolutely wrong to say the PM signalled at any stage that the government would oppose” the amendment. The proposal would have passed comfortably even if the government had not supported it as it had both the support of the Labour party and more than 60 Tory backbenchers, including Jacob Rees-Mogg.

Costa, the son of Italian immigrants, has been quietly lobbying May over EU citizens’ rights for two years.

Alberto Costa MP (@AlbertoCostaMP) 1/4 Can’t begin to say how brilliant it is to see my amendment in black and white on the order paper today. I’m hugely grateful to those colleagues who have very kindly supported my amendment to ringfence rights for those EU citizens in the UK and those in UK citizens in the EU. pic.twitter.com/zrhwN9ljpw

The home secretary also came under sustained attack for the registration system the government is about to launch nationally for EU citizens.

The Labour MP Stephen Doughty described the “settled status” scheme as a shambles and told Javid the basis of registration was discriminatory as it required EU citizens to request rights they already had.

It would also recategorise them in a no-deal scenario as a cohort of the population who did not have rights if they did not have a settled status.

“‘If people are having to secure those rights then, by definition, they don’t have those rights,” Doughty said. “You are at risk of having Windrush all over again.

“In a hostile environment, they are going to be at risk of not being able to access services, not being able to access housing, potentially being detained by the immigration authorities.”