Ugandan police denied the men were in their custody, but Kenyan rights groups lobbied the Ugandan authorities to free them.

In a joint statement, Vocal Africa, the Law Society of Kenya and Amnesty International thanked the Kenyan and Ugandan governments, activists, journalists, diplomats and “all active citizens who have tirelessly campaigned for this moment”.

Former pop star Bobi Wine, whose real name is Robert Kyagulanyi, is running for the presidency in next year’s elections, challenging President Yoweri Museveni, 80, who has held power since 1986.

Wine accused the Ugandan government of targeting the two Kenyans for associating with him.

Ugandan security agencies have often been accused of orchestrating the detention of opposition politicians and supporters while not in uniform. Some of those arrested have later resurfaced in court facing criminal charges.