A still from the Kenyan film Rafiki. Photograph: Courtesy Big World Cinema

It premiered at Cannes, the first Kenyan film to be selected by the prestigious festival, but was banned domestically on the grounds that it promotes homosexuality, a criminal offence under a colonial-era law.

“I am not convinced that Kenya is such a weak society that it cannot handle a gay theme. There are Kenyans who paid the ultimate price for the freedoms we enjoy today,” Justice Wilfrida Okwany told a packed courtroom in Nairobi.

The judge said the makers of the film were now “allowed to admit the film” to Kenya’s Oscars selection committee. A precondition of submission is that a film has been shown for seven consecutive days.

The film’s director Wanuri Kahiu tweeted:

Wanuri (@wanuri)

I am crying. In a french airport. In SUCH Joy! Our constitution is STRONG! Give thanks to freedom of expression!!!! WE DID IT! We will be posting about Nairobi screening soon. Follow @rafikimovie

The film is an adaptation of a prizewinning short story by Ugandan author, Monica Arac de Nyeko.

The Kenya film classification board, which banned Rafiki in April, said it would comply with the court’s orders but criticised an “attempt to normalise homosexuality … akin to air-conditioning hell”.

“It is a sad moment and a great insult, not only to the film industry, but to all Kenyans who stand for morality, that a film that glories homosexuality is allowed to be the country’s branding tool abroad … The board firmly believes films should reflect the dominant values of the Kenyan people. Homosexuality does not qualify as such,” the board said in a statement.

The film’s creators gained widespread support for a legal attempt to overturn the board’s decision.

“There is a history to this story of overreach. In enacting the law on films and stage plays in Kenya, the colonial state viewed artistic expression as inherently subversive and disruptive of the status quo … When art is truthful and fulfilling its social function, it shows the world as changeable and helps in changing it,” Kimani Njogu, a respected linguist and writer, wrote in the Nation newspaper last week.

At least one Nairobi cinema has already announced it will screen the film.