(Adds shooting, Kibaki party statement)
By Katie Nguyen and George Obulutsa
NAIROBI, Dec 27 Millions of Kenyans voted on Thursday in a close-fought national election marred by delays, sporadic trouble and rigging charges from the opposition.
Police fired teargas to disperse an angry crowd in one district, as voters across the east African country's humid coast, shantytowns and lush highlands took part in the tightest contest since independence from Britain in 1963.
In Nairobi's vast Kibera slum, gunmen shot dead one man and wounded two others near a polling station. Police called it an "act of thuggery", while the opposition said the attack was against three of its agents.
President Mwai Kibaki, 76, is vying for the top job with former ally Raila Odinga, 62, who is determined to realise a long-held dream of leading the region's top economy.
Kibaki, whose National Rainbow Coalition unseated Kenya's 39-year ruling party in 2002, faces the possibility of losing his re-election bid despite a sound economic record and the backing of his Kikuyu tribe, the country's largest.
If Kibaki loses, he will be Kenya's first sitting president ousted at the ballot box. Analysts say the chance of a second transfer of power in two elections shows democratic maturity. Others fear it heightens the potential for trouble.
Many of the 14 million eligible voters began queuing long before voting stations opened at 6 a.m. (0300 GMT) for the concurrent presidential and parliamentary votes.
Some Samburu tribesmen, in Kenya's arid north, had to be helped by election officers as they were illiterate.
Because of delays in opening, about a quarter of the 27,000 polling stations were kept open after the 5 p.m. (1400) closing deadline, the Electoral Commission of Kenya (ECK) said.
Chief EU election observer Alexander Graf Lambsdorff said he had seen no evidence of fraud.
Delays earlier in the day stoked tensions in areas including Kuresoi, where police fired teargas to chase away voters furious their names were missing from registers.
Tempers also frayed in Odinga's Nairobi constituency.
After complaining to the ECK that his name was also missing, Odinga -- who has led pre-election opinion polls -- was mobbed by fans as he returned to vote in Kibera, Kenya's biggest slum.
He said the mix-up had been a "deliberate attempt" by the government to rig the outcome in his constituency, but Kibaki's party said he had gone to the wrong voting booth.
"Rigging claims are an attempt to subvert the election process. Raila and his team do not want to accept the results if they lose," Kibaki's Party of National Unity (PNU) said.
Local observers were out in force, up to 20,000.
"There's been a lot of confusion in some places because the ECK has been overwhelmed by the numbers," said Koki Muli, co-chair of a domestic observers' group. "The boxes were opened with no problems, but the tricky time will be the counting."
Kibaki, who voted near his home in Othaya, a fertile central region of tea and coffee farms, said he was sure of victory.
"Kibaki is a true leader," said Othaya businesswoman Wanjiku Muteru. "It's a shame loudmouthed people are spoiling his name."
Many supporters of Odinga, a former political prisoner jailed by Kibaki's predecessor Daniel arap Moi, believe the Kikuyu have had it too good under the current administration.
"We didn't celebrate Christmas," said Feni Ojwang, a housewife in Odinga's Nyanza birthplace, a western region of picturesque valleys that belie its deep poverty.
"The goat and chicken I bought are still in the house. We will not slaughter them until Raila is declared winner."
While Kenya enjoys a reputation as a haven of stability in a volatile region, it has a long history of election violence.
Odinga's Orange Democratic Movement (ODM) unleashed a last minute barrage of claims that Kibaki's Party of National Unity (PNU) was planning to steal victory on the eve of the vote.
The PNU denied it. As tensions rose, mobs in Nyanza killed three policemen this week who they accused of being disguised as PNU agents to stuff ballot boxes.
Police boss Hussein Ali said 60,000 police and security agents were sent to more than 20,000 polling stations. He warned agitators: "If it means shooting them, we will shoot people."
While Odinga's outspokenness contrasts with Kibaki's more measured character, both pledge to boost growth and provide free secondary education.
First official results are expected early on Friday.
The candidate who receives more votes than his closest challenger, plus 25 percent in five of eight provinces will win. (Additional reporting by Guled Mohamed in Kisumu, Florence Muchori and Bryson Hull in Othaya, Nicolo Gnecchi and Tim Cocks in Nairobi; Editing by Andrew Cawthorne and Mary Gabriel)