Kenyans stood patiently in long lines on Monday to elect a new president but machete-wielding youths on the coast killed four policemen, casting a shadow over a vote seen as vital to repairing Kenya's image after tribal bloodshed five years ago.
A few hours before the 6am (4pm New Zealand time) start of voting and with long queues formed across the nation before sunrise, four police officers on patrol in the Mombasa port city area were hacked to death by attackers, a senior police officer said.
Officials and candidates have made impassioned appeals to avoid a repeat of the tribal rampages that erupted following the disputed result of the 2007 election. More than 1200 people were killed, shattering Kenya's reputation as one of Africa's most stable democracies and bringing its economy to a standstill.
But as in 2007, the race has come down to a high-stakes head-to-head between two candidates, Prime Minister Raila Odinga and Deputy Prime Minister Uhuru Kenyatta. Once again both will depend heavily on votes from loyalists from their tribes.
Ambrose Munyasia, chief of police intelligence in the Coast region, said he suspected the gang behind Mombasa attack were linked to a separatist movement, the Mombasa Republican Council, which had in past weeks sought and failed to have the national vote scrapped and a referendum on secession instead.
If so, it would suggest entirely different motives that sparked the post-2007 vote rampage, when disputes over the result fuelled clashes between tribal loyalists of rival candidates. That could limit the impact of Monday's attack.
Bernard Otundo, 36, with others quietly queuing in Nairobi in early morning darkness, said he expected a peaceful vote.
"Some of us have been here as early as 2am this morning. I got here slightly after 3am," he said. "There has been a lot of awareness campaigns against violence and I don't think it will happen this time around, whatever the outcome."
Kenya's neighbours are watching nervously, after their economies felt the shockwaves when violence five years ago shut down trade routes running through east Africa's biggest economy. Some landlocked states have stockpiled fuel and other materials.
The United States and other Western countries are worried about the election in a country seen as a vital ally in the regional battle against militant Islam. Adding to election tensions, al Shabaab militants, battling Kenyan peacekeeping troops in Somalia, issued veiled threats before the vote.
Kenyans were undeterred as long lines quickly formed across the nation. In the early hours before voting, some Kenyans blew whistles and trumpet-like "vuvuzelas" to wake up voters. But Kenyans still remain fearful that violence could flare.
"Our future is uncertain but we long for peace and victory is on our side this time round," said Odinga supporter 32-year-old Eunice Auma in Kisumu, a flashpoint after the 2007 vote.
"However, should our candidate (Odinga) fail to clinch victory. I'm afraid violence will erupt," she said.
Outgoing President Mwai Kibaki, barred from seeking a third five-year term, made what he described as a "passionate plea" for a peaceful vote. The candidates have pledged to accept the result. But the close race has raised the sense of uncertainty.
Though well ahead of six other contenders, polls suggest Odinga and Kenyatta will struggle to secure enough ballots for an outright victory in the first round. That could set the stage for a tense run-off tentatively set for April 11, while a narrow first-round win could raise prospects for challenges.
The West is fretting about the outcome because one leading candidate, Kenyatta, has been indicted by the International Criminal Court with his running mate, William Ruto, for orchestrating the post-2007 vote violence. He denies the charges. But, if he wins, it would present a diplomatic dilemma for Western nations that are big aid donors to Kenya.
"There are those who said that Uhuru and Ruto will not run because we are facing cases in Europe, but God has opened that road for us so that people can decide," Kenyatta, 51, told a final rally in Nairobi's central park.
To try to prevent a repeat of the contested outcome that sparked the violence after the December 2007 vote, a new, broadly respected election commission is using more technology to prevent fraud, speed up counting and increase transparency.
This could lead to a swifter announcement of results, after delays in 2007 fuelled the crisis. Provisional figures may emerge within hours of polls closing, although the commission has seven days to declare the official outcome.
Some voters still grumbled about the slow process as lines snaked hundreds of metres (yards) from the polling station. "People are beginning to fall and faint on the queue," said Peter Gichuchi, waiting for hours in the steamy heat of Mombasa.
To build confidence, Kenya has passed a new constitution since 2007, police chiefs have deployed extra forces to maintain security and there is a more independent judiciary which commands greater respect. Officials have appealed to candidates to raise any challenges in the courts and not on the streets.
Even so, Odinga has raised a warning flag, telling Reuters two days before the vote that the commission had by "design or omission" failed to register all voters in his strongholds, putting him at a disadvantage, a charge the commission denies.
"I am confident we are going to win these elections in the first round," said Odinga, 68, the loser in 2007 who may now have his last chance at the top job. In comments after voting in Nairobi, he also condemned the Mombasa killings.
Kenyans, hoping for a peaceful vote, say memories of the brutal killings by gangs armed with machetes, knives and bows and arrows are still fresh enough to deter a repeat. Many want to see a peaceful election and a result that will not damage Kenya's economy, which has taken years to recover from the bloodshed last time.
"By the end of the day, I want to see the youth with jobs," said Tony Wamagata, 23, who works on a casual basis as a bus conductor. He lined up with many others at a polling station in a church on the outskirts of Nairobi.
Yet many are still wary, particularly in places where violence erupted last time. Shopkeepers have run down stocks and some people in mixed tribal areas have returned to their homelands elsewhere, a few worried by threatening leaflets.
"We have confidence in the elections but if it's stolen, I don't think there can be peace. Not unless it's a clean win," said Vitalis Odhiambo, 34, an Odinga supporter in the teeming Nairobi slum of Kibera, where many of the corrugated iron shacks were destroyed in the rampage after the December 2007 election.
Michael Ochieng, in Kisumu on the shores of Lake Victoria where businesses were looted five years ago, said reports of threatening leaflets in areas of the Rift Valley, another site of slaughter after 2007, did not bode well.
He spoke of growing animosity between Odinga's Luo tribe and Kenyatta's Kikuyu, in a contest where many voters will make their decision based on tribal loyalties rather than ideology.
Alongside the presidential race, there are hotly contested elections for senators, county governors, members of parliament, women representatives in county assemblies and civic leaders.
Family counts blessings after superbug scare (graphic content)