Kenyans turned out in massive numbers on Monday to vote in a general election described as the most important, and nervously anticipated, in the country's 50-year history.

Despite multiple attacks on security forces that left a dozen people dead on the coast and reports of gunmen seizing control of two polling stations in Garissa, near the Somali border, the prevailing mood was one of relief as millions waited peacefully and patiently to cast their vote. For most, epic queues and computer glitches were a bigger headache than the much-predicted tribal conflagration.

Provisional results, based on more than a quarter of polling stations reporting, showed Uhuru Kenyatta – who is due to stand trial at the international criminal court – leading with 55% of the vote, well ahead of his main rival, Raila Odinga, on 40%.

Throughout most of the country millions of Kenyans waited in long lines and cast their ballots in peace. Monday's election was Kenya's first since more than 1,000 people were killed in violence following its December 2007 presidential election.

But this was the easy part. There are still many hurdles to come, as a tight contest for the presidency could lead to a run-off vote and ugly disputes both in the courts and on the streets.

East Africa's biggest economy is desperate to avoid a repeat of 2007's ethnic violence that left more than 1,100 people dead and 600,000 displaced.

Officials, candidates and media have made impassioned pleas for peace, and there is extraordinary international scrutiny and pressure.

Before dawn, early-bird Kenyans blew whistles and trumpet-like vuvuzelas to wake the country's 14.3 million voters. With queues forming well before polls opened at 6am, it soon became clear the turnout would be "huge", officials said, possibly a record. The system struggled to cope with the demand, and some voters waited up to 10 hours to cast their ballots.

Anti-fraud fingerprint-based voter-ID technology, introduced to counter the allegations of rigging that erupted last time, broke down in many areas. Officials said many polling stations opened late and there were problems with transporting election material.

In the capital, Nairobi, there were few cars on the streets but long lines of people snaking for several hundreds of metres, some holding umbrellas to deflect blazing sunshine.

In Kibera, the biggest slum in Africa and a potential flashpoint, a man in a Manchester United shirt could be seen painting "Peace" in the middle of the road. Speed bumps had been decorated with the words "Peace wanted alive" and "Peace love unity" with the CND symbol.

Thousands of people queued patiently past goats, open sewers, piles of uncollected rubbish and walls coated from top to bottom with weathered campaign posters. Most of the rickety market stalls and corrugated iron shops were shuttered.

Odinga, who has been MP for Kibera for 20 years, voted at a local primary school and said: "Never before have Kenyans turned up in such numbers. I'm sure they're going to vote for change this election."

Others faced a longer wait to vote at the school, where the much-heralded computer system had been knocked out by flat batteries, forcing staff to revert to manual registration.

"I expected the computers to work and I'm getting frustrated," said Eric Wasike, 27, a computer repair man who had been queuing for five hours. But, like many here, he believed the outcome could improve lives in Kibera. "It's important to vote because in the past politicians looked after their own needs, but now I'm going to vote for a person who will bring change in society. The next generation will benefit from it."

He added: All of us are optimistic. No matter what the outcome, Kenya will remain Kenya. We don't need to resort to violence to get our rights. The entire world is watching us and we are going to set an example. We don't want a repeat of what happened last time."

Further back in the queue, Ibrahim Hassan, 49, a driver, said: "It's OK to wait, because we are trying to make history. If you want to do something good, you have to be patient."

But Janet Wasike, 19, cradling her one-month-old son, Fabian, had arrived to discover her name was missing. "I'm feeling bad because I've lost my vote," she said.

Elsewhere, in Starehe constituency, voices were raised as people argued with officials but the mood was mostly calm. Mohamed Mahmoud, 54, a retail manager wearing sunglasses and a flamboyant patterned shirt, said: "It's the first time I've seen so many people eager to come out and vote. Definitely it will end peacefully. People have learned a lesson from 2007. The new constitution has changed the landscape. Both sides have persuaded Kenyans to accept defeat peacefully and I don't think they will go back on their word."

Mohammed Ahmed, 23, a student, was stuck at the back of the mammoth queue. "I feel disgusted, I feel like going home. There's an option to wait until 2017 [the next election]. But I want to cast my vote to change the way things are going."

Around the port city of Mombasa, however, the day got off to the kind of start many had been dreading: 200 members of a coastal separatist group armed with guns, machetes and bows and arrows set a trap for police in the pre-dawn hours, killing five officers, Kenyan police inspector general David Kimaiyo said. One attacker also died.

A second attack by secessionists in nearby Kilifi killed one police officer and five attackers, Kimaiyo added. A Kilifi police official, Clemence Wangai, said seven people had died in that assault, including an election official.

A spokesman for the separatist Mombasa Republican Council denied it was behind the assaults. "We are not responsible for any attacks anywhere in this region," Mohammed Rashid Mraja told Reuters, adding that the group sought change through peaceful means only.

Meanwhile, the Islamist militant group al-Shabaab urged Muslims not to vote and repeated calls for Kenya to withdraw its peacekeepers from Somalia. A grenade attack on a police post in Garissa, a city near Somalia, killed two civilians, police said. A bomb exploded in the Mandera area, also near the border, causing no fatalities.

Farah Maalim, deputy speaker of parliament, said the attacks on the Garissa polling stations took place after dark. Gunshots and an explosion rang out as gunmen stormed the stations and seized election material. Separate attacks on the coast killed 19 people early on Monday.

About 99,000 police officers were on duty during the election. Along with the presidential race, there are hotly contested elections for senators, county governors, members of parliament, female representatives in county assemblies and civic leaders.

Christopher Kibanzanga, an election observer from Uganda's National Consultative Council, told the Associated Press: "This can only be likened to South Africa when [President Nelson] Mandela was elected. The people have turned up in large numbers. The spirit of patriotism and nationalism has come back. I think this is a perfect process."