Former senior British military advisor Major General Chip Chapman joined several military figures in criticising Harry's claim in his memoir Spare, branding it "crassly and naively stupid" as well as "disloyal".
He also warned that Harry's book opens him up to "every jihadist and nutcase out there".
One Taliban leader has also condemned the duke for describing those he killed as “chess players".
Maj Gen Chapman said Harry's claims had broken the values of: respect for others, integrity, loyalty, and selfless commitment.
In his autobiography, of which copies have been seen ahead of its official release on Tuesday, Harry reportedly writes about his two tours of Afghanistan, in 2007/8 and 2012/13.
His accounts include a series of bombshell claims, including the story of a physical fight between him and brother William over a conversation about Meghan.
His claim that he killed 25 people during his tours of Afghanistan, saying it was something he was neither proud nor ashamed of, has also attracted criticism from military figures.
Read more: Did Prince Harry write the book himself?
Speaking to Times Radio, Maj Gen Chip Chapman, a platoon commander in the Falklands conflict, said: "We have a code of conduct. It's the values and standards of the military and he's broken at least four of those values that include respect for others, integrity, loyalty, and selfless commitment.
"You can't be any more disloyal, either both to the Crown and the Crown being a member of your family, so from both of those perspectives it's not really good."
He added: "It's crassly and naively stupid from Harry, his publishers and his ghost writer."
Maj Gen Chapman, former head of counter-terrorism at the Ministry of Defence, said while Harry is no longer a serving member of the military, books such as his often exclude sensitive details such as casualties in Iraq or Afghanistan but that the duke's places him and his family in greater danger.
He added: "For him, who wants privacy and security, he's just opened himself up to every jihadist and nutcase out there."
He also said he had never come across the "body count mentality" Harry seemed to be demonstrating by pinpointing the number of people he had killed, saying he had "never, ever" come across it in the forces.
"It's an awful lack of judgement and maturity. It's a naive approach to how the miltary should act.
"Also he was not on the ground. There's no way that he could ID anyone or bury them so to give a specific number is, quite frankly, slightly ridiculous."
In the book, which was released early by mistake in Spain, Harry says he would watch a video of every "kill" from a camera attached to the nose of the helicopters he flew, saying: "It seemed to me essential not to be afraid of that number.
"So my number is 25. It’s not a number that fills me with satisfaction, but nor does it embarrass me."
Watch: Why did Prince Harry's memoir Spare get released early?
Chapman is not the only military figure to criticise Harry's revelations over his time in Afghanistan.
The security warnings were echoed by Colonel Richard Kemp, who served in Afghanistan. "In terms of the numbers he’s talking about… He himself is already under threat... and by resurrecting it in quite such stark terms now undermines his own security;" Col Kemp told the BBC.
"That sort of figure that doesn’t need to be given. It will remind people that 10 years ago there was this very high-profile man killing people that they might have sympathy for in Afghanistan and might well be provoked to attempt revenge."
Anas Haqqani, Taliban leader in Afghanistan, condemned the duke for describing those he killed as “chess players”, but added that not many who killed Afghans “have your decency to reveal their conscience and confess to their war crimes”.
Lord Darroch, former national security adviser, said he “would have advised against” Harry revealing those details, while former commando Ben McBean told the prince to “shut up”.
Colonel Tim Collins, known for a pre-battle speech he made in Iraq, said Harry has now turned against his “other family, the military”.
He told Forces News on Friday: “Amongst his assertions is a claim that he killed 25 people in Afghanistan.
“That’s not how you behave in the Army; it’s not how we think.”
Former Royal Marine, Conservative MP for Beckenham Bob Stewart, who served seven tours in Northern Ireland and led UN troops in Bosnia, told the Daily Mail: "I wonder why he is doing such things. Real soldiers tend to shy away. People I know don't boast about such things. They rather regret that they have had to do it."