The former head of NHS Digital has said he was put under "immense pressure" by the Home Office under Theresa May to release data on immigrants despite his concerns over its legality.
Kingsley Manning said he was challenged for "daring" to question if there was a legal basis for handing over confidential patient data that would help the Home Office trace suspected illegal immigrants.
Last month, the Home Office published an agreement showing the basis by which information can be requested from NHS Digital.
But Mr Manning said the NHS body has been forced to hand over data that the Home Office would find useful since "at least" 2005, sometimes to junior officials who would just "ring up" and ask for it.
In an interview with the Health Service Journal (HSJ), Mr Manning said: "We said to the Home Office: 'We need to understand what the legal basis of this is.'
"The Home Office response was: 'How dare you even question our right to this information. This is data that belongs to the public. It is paid for by the taxpayer. We should use it for public policy'."
When Mr Manning launched a review to establish a clear legal framework for the data sharing, there was an "enormous reluctance from both the Home Office and the Department of Health to clarify any element of this process", he said.
"The Home Office view was that tracing illegal immigrants was a manifesto commitment.
"If I didn't agree to co-operate [with the sharing of patient data] they would simply take the issue to Downing Street."
The new agreement announced last month has "maximised" Home Office powers "to the absolute limit", Mr Manning said.
He added: "All the Home Office has to say now is: 'We have lost track of this individual', and NHS Digital will have to hand over confidential patient information, such as the patient's name, gender, date of birth, last registered address and area details of their GP.
"There is no provision for transparency, no provision for oversight or scrutiny and there is no role for the National Data Guardian.
"Nor is there any provision to alert patients to the possibility that information from their NHS patient record could be passed on to the Home Office."
Mr Manning said he had become "deeply concerned" once he took the helm of the NHS body in 2013 that data had been handed over since at least 2005.
"We were supposed to be a safe haven for patient data, and here we were giving out information on thousands of people a year to the Home Office, without any transparency or oversight," he said.
And he said the Home Office was "pretty upset" by the idea that the number of tracing requests from the Government department should be published.
He said: "I made it clear that NHS Digital needed to understand the legal basis for the exchange of data.
"We were in a position where we would have a relatively junior official from the Home Office ring up and say: 'On my say-so I'd like the information on the following person'.
"But as far as I could see there was no reporting of this, other than as a declaration."
Mr Manning commissioned an external review, chaired by Professor Maria Goddard, director of the Centre for Health Economics at York University.
The review has been completed but not published.
He said: "I came under immense pressure to leave matters as they were - particularly after the 2015 election when immigration became a fundamental political issue.
"The threat was that if we pursued this line of questioning we would be deemed to be an 'insufficient partner' within the system.
"My key concern has always been that highly vulnerable people will be deterred from accessing the health system because they are worried that their information will be shared with the Home Office."
Join our new commenting forum
Join thought-provoking conversations, follow other Independent readers and see their replies