NAIROBI, Kenya — With a hotly contested, anxiously awaited presidential election only three weeks away, Kenya tried something new on Monday night: it held a debate.

Just after sunset, millions of Kenyans sat down in front of television sets or grabbed transistor radios to witness the first time presidential candidates faced off against one another in a public forum in Kenya’s nearly 50 years as an independent nation.

Kenya may be one of the most developed and powerful countries in Africa, known for its safaris and historically close to the West, but its politics have been bedeviled by corruption, impunity and bitter ethnic rivalries, often exploding into widespread violence during contested elections.

Human rights groups, intellectuals and the Kenyan media are now doing all they can — like setting up social media watchdogs and organizing presidential debates — to make sure that this time history does not repeat itself.