LONDON — Britain’s home secretary has apologized to hundreds of immigrants who were illegally forced to provide DNA samples as part of a visa application process to settle in the country.

In a speech to Parliament on Thursday, the home secretary, Sajid Javid, said that an internal review had found that more than 400 immigrants — including relatives of Gurkha soldiers and of Afghan nationals who had served the British government — were sent letters demanding DNA tests to prove they were related to British citizens.

Those seeking visas to remain in Britain on the basis of a family relationship can choose to provide DNA evidence to support their application, but the provision is not mandatory by law.

“At the end of June, we became aware of some immigration cases where the provision of DNA evidence had been made a requirement, and it was not simply a request,” Mr. Javid said.