The Home Office will no longer use NHS records to track down illegal immigrations, ministers have announced.
The move came after MPs raised concerns the policy breached patient confidentiality and could deter people from seeking treatment.
Now the rules will be tightened so records can only be shared in cases “involving serious criminality”.
The move has been welcomed by doctors’ groups as a “huge victory for common sense”.
The government had been facing a possible defeat as MPs debated the Data Protection Act.
Conservative MP Sarah Wollaston, who chairs the health select committee, had lodged an amendment to change the rules and the government was facing a possible defeat.
Digital Minister Margo James said the government had reflected on the concerns she raised – “and with immediate effect, the data-sharing arrangements between the Home Office and the NHS have been amended”.
She added: “The bar for sharing data will now be set significantly higher, by sharing I mean between the Department of Health, the Home Office and in future possibly other departments of state, no longer will the names of overstayers and illegal entrants be sought against health service records to find current address details.”
Ms James told MPs that the data would only be used in future “to trace an individual who is being considered for deportation action having been investigated for or convicted of a serious criminal offence”.
Ms Wollaston said she was “delighted” the government backed her campaign.
Dr John Chisholm, chair of the BMA ethics committee, described the government’s concession as a “positive step”.
He said: “The relationship between doctor and patient is based on a foundation of confidentiality and trust.
“If this breaks down, it not only damages this individual relationship, but also is likely to have knock-on effects on the healthcare-seeking behaviour of the public at large.”
Professor Helen Stokes-Lampard, chair of the Royal College of GPs, said: “We are extremely pleased and relieved that the government has suspended the data-sharing agreement that has been in place with NHS Digital – it is a huge victory for common sense, for civil rights and for high-quality patient care.”
Migration officials’ access to NHS records tightened}