Under heavy security, millions of Kenyans voted Monday in nationwide elections that will usher in a new presidential era, even as marauding gangs killed six police officers in the southern coastal city of Mombasa.

The vote came five years after post-election violence splintered this strategic East African nation and devastated its economy. Despite the new bloodshed, Kenyans across Nairobi and in most parts of the country patiently waited for hours in long, snaking lines to cast ballots for presidential, parliamentary and provincial candidates.

The voting unfolded peacefully in most parts of the nation, despite problems with digital equipment and delays at some polling stations. The turnout — about 14 million Kenyans are registered to vote — is predicted to be the biggest in the country’s history. Results in the presidential race are expected as early as Tuesday.

“It’s very different from 2007,” said Ruth Namulundu, an election monitor in the Nairobi slum of Kibera, an epicenter of the violence that ignited after the December 2007 elections. “It’s more calm now. If the voting continues like this, everything will be fine.”

Still, a predawn assault on Monday that killed the six police officers in Mombasa served as a reminder of the existing tensions and how easily violence can erupt. Police officials said a gang of 200 men wielding machetes clashed with police who were deployed to keep the peace during the vote. Police said the assailants were suspected of being members of the Mombasa Republican Council, a regional separatist movement that opposes the elections.

Kenyan authorities and candidates have publicly called for a calm and peaceful vote to prevent a repetition of the violence that followed the disputed 2007 election. More than 1,000 people were killed and hundreds of thousands displaced as opposing tribal mobs killed neighbors and burned houses, churches and shops. On Monday, more than 100,000 police officers and soldiers were on patrol and stationed at polling stations.

This year, national surveys show a tight race between Prime Minister Raila Odinga and his main rival, Deputy Prime Minister Uhuru Kenyatta. Six other candidates also are vying for the presidency. Most observers expect that neither Odinga nor Kenyatta will win more than 50 percent of the vote, requiring a runoff election scheduled for April.

It was Odinga’s bitter loss to outgoing President Mwai Kibaki that ignited the ethnically charged attacks in 2007, mostly pitting Odinga’s Luo tribe and Kibaki’s Kikuyus. Kenyatta, also a Kikuyu, and his running mate, William Ruto, were indicted by the International Criminal Court (ICC) at The Hague, accused of instigating the mobs that perpetrated the violence. If they are elected, they could face a significant portion of their term on trial for crimes against humanity.

Long a key U.S. ally, Kenya is an important counterterrorism partner in the fight against al-Shabab, a militia linked to al-Qaeda in neighboring Somalia. Kenya is also an economic powerhouse, vital to keeping stability in the region.

On Monday, Odinga, Kenyatta and Ruto urged their followers to preserve the peace, no matter who wins.

“This nation will have a president, and that president will represent all Kenyans,” Kenyatta told a gathering of supporters Monday.

In the Nairobi slum of Mathare, where Kikuyus and Luos live side by side, the tensions were palpable. Both communities have been fueding since Kenya’s independence in 1963. No Luo has ever held the presidency, while Kikuyus and Kalenjin, Ruto’s tribe, have ruled Kenya.

“The Kikuyus are already on the throne,” said Benjamin Ogola, 27, an unemployed worker, as his friends nodded in agreement. “We have to remove the Kikuyu and select Raila. We want a Luo to lead the country.”

Kikuyu voters said they supported Kenyatta, and believed he was not guilty of the ICC charges. “We are going to win,” said Chege Kimani, 60, a retired teacher, shortly after he voted. “There will be no runoff.”

In Kibera, a stronghold of Odinga, many voters said it was impossible that their candidate could lose.

“We expect Odinga to win outright in the first round,” said David Misati, 35, a teacher.

When asked what would happen in Kibera if Kenyatta won in the first round, he paused, and then replied, “There will be a problem then.”