Human rights campaigners have voiced outrage over a 13-year-old Afghan boy jailed for having sex with two adult men, urging the government to release him and punish his abusers.

The boy, accused of having sex with two men in a public park in the western province of Herat, was sentenced to one year in juvenile detention, Human Rights Watch (HRW) said in a statement on Sunday.

Afghan law bans "pederasty", sex between a boy and a man, but HRW said "moral crimes" charges, which include all sexual relations outside of marriage, have been used to punish the victim of a criminal offence.

"When a man has sex with a 13-year-old child, the child is a victim of rape, not a criminal offender," Brad Adams, Asia director at HRW, said in a statement.

"The Afghan government should never have victimised this boy a second time, but instead should have released him immediately with urgent protection and assistance."