"Following a detailed assessment of the risks by the operational chain of command, the decision has been taken... to withdraw Prince Harry from Afghanistan immediately," the UK defence ministry said in a statement.
The UK statement went on: "This decision has been taken primarily on the basis that the worldwide media coverage of Prince Harry in Afghanistan could impact on the security of those who are deployed there, as well as the risks to him as an individual soldier."
'I don't like England'
In comments made available to the British media, Harry said he was enjoying being in a combat zone and not "sitting around" in Windsor, the town outside London where the royal family has a castle and Harry's regiment has its headquarters.
Asked if he would ever want to come back to Afghanistan, he said: "I don't want to sit around in Windsor.
"But I generally don't like England that much and, you know, it's nice to be away from all the press and the papers and all the general sh*te that they write."
The comments are unlikely to be welcomed by Harry's supporters in Britain or by the popular tabloid press.
Harry, 23, sparked widespread public anger in the UK in 2005 when he was photographed at a fancy dress party dressed in a Nazi uniform.
In London he is frequently photographed leaving nightclubs, apparently drunk, with his girlfriend, and has been in trouble with his father Prince Charles for smoking cannabis.
British newspapers were full of praise for the prince on Friday, before the comments were made public, calling him a "hero" and a "model soldier".
Harry is the first member of the royal family to go to war since the Falklands conflict with Argentina 25 years ago.