South Korea's Constitutional Court has upheld the nation's ban on outlawing gay sex in the military, the AFP reported.

Saying that the law was necessary to maintain discipline among the ranks, the 9-member panel ruled Thursday that the law is constitutional.

“The legal code cannot be seen as discriminatory against gays because such behavior, if left unchecked, might result in subordinates being harassed by superiors in military barracks,” the court said in a statement.

Justices, however, were not unanimous in their decision, with 4 judges dissenting.

Under the ban, written in 1962, soldiers found guilty of violating the policy are locked up for up to one year and given a dishonorable discharge. South Korea's military draft makes service mandatory for all male citizens, with no conscientious objector option. And in a country where service records are commonly used to determine employment and being gay is considered “abnormal,” a military dishonorable discharge for being gay carries a heavy burden.

The Military Penal Code further punishes gay troops by lumping together consensual and non-consensual gay sex as “sexual harassment.”

South Korea's defense ministry had asked the Constitutional Court to uphold the gay ban, saying that the military “works for the public interest rather than personal happiness.”