You are not permitted to download, save or email this image. Visit image gallery to purchase the image.
The issue will be an embarrassment for Cameron's Conservative-led government which has pledged to bring down the number of immigrants to below 100,000 a year by 2015.
Trailing in the polls ahead of European elections in May and national polls next year, Cameron is striving to stem a right-wing threat from the anti-immigration UK Independence Party.
Cameron had accepted the resignation with regret, his office said. "There is no suggestion that Mr Harper knowingly employed an illegal immigrant," the statement read.
In an exchange of letters with Harper, dated Friday (local time) and released by Downing Street, Cameron said: "I am very sorry indeed to see you leave the government, but I understand your reasons for doing so.
"In particular, I understand your view that, although you carried out checks on your cleaner, you feel that you should hold yourself to an especially high standard as Immigration Minister. You have taken an honourable decision."
Harper was elected Conservative MP for the Forest of Dean in Gloucestershire in 2005 and was appointed immigration minister in 2012. He was told that the cleaner did not have indefinite leave to remain the UK earlier this week, he said.
He added in his resignation letter to Cameron that he had checked the cleaner's immigration status when he first employed her in 2007.
"When you then appointed me as Immigration Minister ... I went through a similar consideration process and once again concluded that no further check was necessary," he added. "In retrospect, I should have checked more thoroughly."
Harper will stay on as a member of parliament.