A Zambian magistrate has acquitted two men charged with having sexual relations "against the order of nature", saying the state failed to prove its case.

Philip Mubiana and James Mwape, both in their early 20s, have been in custody since May last year and faced up to 15 years in jail if convicted.

The case drew the attention of rights groups and governments concerned that Zambia may be hardening its stance on gay rights following tough new laws in Uganda and elsewhere in Africa.

The two men were arrested after being reported to the police by one of Mubiana's relatives.

Outside the court in Kapiri Mposhi, 200km north of Lusaka, several local residents denounced Western governments for their support of the pair.

In February, another Zambian magistrate acquitted prominent gay, lesbian and transgender rights activist Paul Kasonkomona on charges of encouraging homosexuality after concluding that the prosecution failed to prove its case.