Justice Wilfrida Okwany said that during a seven-day period, the film, a lesbian love story produced in Kenya, can be screened to willing adults. The ruling means that Rafiki will be eligible for Oscar consideration as the best foreign-language film.
Kenya's Film and Classification Board banned Rafiki in April, just hours before it premiered at the Cannes Film Festival in France.
Directed by Wanuri Kahiu, it was the first Kenyan film ever chosen to be screened at the festival.
Rafiki, the Swahili word for "friend," is a film about two girls who fall in love and as a result become outcasts in their community.
The Kenyan film board banned it for its homosexual theme. Board CEO Ezekiel Mutua said the film had "a clear intent to promote lesbianism in Kenya."
Kahiu filed a suit against the board on September 10, leading to Friday's ruling. Carol Liam, a lesbian activist in Nairobi, was elated over the judgment.
"Today is a victory not just for members of the LGBTI community, but a victory for everyone who upholds human rights. The old colonial laws have caused us a lot of grief, we are glad that the cords are being broken slowly by slowly," Liam said.
After the ruling, Kahihu tweeted "Our constitution is STRONG! Give thanks to freedom of expression!!!! WE DID IT! We will be posting about Nairobi screening soon."
Time is of the essence. For the film to be eligible for Oscar consideration as best foreign-language film, it must be screened in its country of origin for seven days before the Sept. 30 deadline.
Mutua, the head of the film board, expressed outrage over the court's decision in a series of tweets. One read, "It would be a tragedy and a shame to have homosexual films defining the Kenyan culture."
In a press release, Mutua said the ruling "was a sad moment and a great insult, not only to the film industry but to all Kenyans who stand for morality."
He also warned the board is watching to see which theater will show the film without the board's approval. Homosexuality is illegal in Kenya and punishable by up to 14 years in prison.
On Thursday, a Kenyan court is set to rule on another landmark case that seeks to repeal sections of the penal code that criminalizes gay sex in Kenya.
The National Gay and Lesbian Human Rights Commission argues that sections 162, 163 and 165 of the code are in breach of the constitution and basic rights of Kenyan citizens.
The laws were introduced in Kenya in 1897, when the country was under British rule.
In April, British Prime Minister Theresa May said she "deeply regretted" Britain’s legacy of anti-gay laws in its former colonies and urged those countries to overhaul what she called "outdated" legislation.