A British pensioner facing charges in Uganda of trafficking obscene publications is to be deported.
Bernard Randall, 64, of Faversham in Kent, pleaded not guilty after police found photos of him having sex with another man on his laptop.
The device had been stolen and files from it were passed to a tabloid scandal sheet. Randall, who was charged alongside his 30-year-old friend Albert Cheptoyek, could have faced a two-year sentence if found guilty.
But Judge Hellen Ajio ordered his immediate deportation within 12 hours and the removal of all charges.
An official from the prosecutor's office said that Randall was being deported because he had "kept on corrupting Uganda's youths".
Randall shouted "Lies!" in court. His lawyer, John Onyango, said there would be no appeal against the ruling.
Cheptoyek is still charged with gross indecency and could be jailed for seven years.
Homosexuality is illegal in Uganda and is punishable by up to 14 years in prison. President Yoweri Museveni refused to sign an anti-homosexuality bill which was already passed by the parliament in December.
The bill proposed life imprisonment for homosexual offences.
Randall, a former computer systems expert, first travelled to Uganda in 2011 after the death of his wife. He returned to Uganda in September. He came out as homosexual after his wife's death.