Residents of Mathare, a slum in Nairobi, prepare for Tuesday's presidential election. (Kevin Sieff/The Washington Post)

A concrete bridge and a narrow, garbage-filled river divide the slum of Mathare into two parts, a space between ethnic groups and voting blocs that are competing fiercely — and many say dangerously — over Kenya’s presidential elections scheduled for Tuesday.

Here in one of the most economically successful and stable countries in East Africa, Mathare is only a few miles away from Nairobi’s rising skyline. Tech firms have popped up on the city’s periphery. Every week, thousands of tourists pile into sleek safari trucks. This spring, the top U.N. humanitarian official here, Siddharth Chatterjee, called Kenya “a beacon of hope in a region mired in fragility.”

But with the election approaching, Mathare feels far from stable. On one side of the rutted bridge is a community of ethnic Kikuyus, the tribe of incumbent Uhuru Kenyatta, 55. On the other side are the Luos, the tribe of opposition candidate Raila Odinga, 72.

Most days, those tribes peacefully coexist, as the slum is consumed by honking minibuses and a frenzy of commercial activity, with traffic moving across the bridge in both directions. But as the election approaches, it is a line not to be crossed.

“This is the front line,” said Stephen Maina, a Kikuyu shopkeeper.

“Where it all goes down,” said Akal Nicholas, a Luo lab technician.

On Friday, families were packing their belongings, preparing to leave the slum before possible violence. Stores were shuttering. Extra firetrucks had reportedly been hired. A senior police officer in the slum said, “We are preparing,” but declined to elaborate.

For all of Kenya’s success and modernization, its elections are still decided almost exclusively by ethnicity, with the Kikuyus and Luos at the forefront of a fractured electorate, where ideology is obscured by identity politics. Since Kenya became independent in 1963, three of its four presidents have been Kikuyu, the first being Kenyatta’s father, Jomo Ken­yatta. A Luo has entered, and lost, every presidential election.

“Now, it is our time,” Nicholas said.

In 2007, a tightly contested race devolved into ethnic violence that left 1,200 dead, with swaths of Mathare burning to the ground and young men clashing with machetes. Kenyatta and William Ruto, his current vice president, were among those charged by the International Criminal Court for inciting violence. Both cases were later dropped for lack of evidence.

Odinga, the son of a former vice president and himself a prime minister from 2008 to 2013, has lost three presidential elections since 1997. It’s likely that this might be his last attempt at the presidency, and Odinga has already said that the only way he could lose is if the results are rigged. For years, seemingly unfounded rumors have swirled in Mathare that if he wins, the Kikuyu section of the slum will be demolished and a stadium named after Odinga will be built in its place.

Last week, when Chris Msando, an election official, was found dead, with signs of torture on his body, Odinga supporters said it was an early sign that the vote could be marred. Msando was one of few officials with access to the country’s computerized voting system. So far, there are no indications of who killed him. Human Rights Watch called his death “catastrophic” for the election preparations.

In speeches, and on their billboards and websites, Odinga and Kenyatta make little overt mention of tribal alliances. Kenyatta talks about the new national railway that recently opened and improvements to maternal health. Odinga says his team offers an alternative to an administration plagued by allegations of corruption, where wealth remains concentrated in the hands of a few. Although Kenya’s average per capita income is more than $1,400 annually, a vast number of citizens live on a small fraction of that.

Behind the scenes, both candidates have put together tribal alliances that they hope will bring the majority of the vote. And both have spent untold millions on their campaigns, buying fleets of SUVs and painting them in their party’s colors.

“There’s no ideological daylight between the candidates,” said Murithi Mutiga, a researcher for the International Crisis Group. “It’s just about numbers that the ethnic alliances will bring them.”

Kenya’s next president will have crucial decisions to make across a number of issues, even if those issues won’t sway the country’s tribally minded electorate. Its military is mired in a bloody war against insurgents in Somalia, who have created a foothold in parts of Kenya. This country remains a haven for refugees from Somalia and South Sudan, but politicians have for years contemplated closing its largest refugee camps. It is crowded with NGOs trying to eradicate poverty and improve education and health access, but the government has much further to go in fulfilling its own development role.

For now, the election polls indicate an extraordinarily close race, mostly showing Kenyatta with a slight edge. The closer the results are, the higher the probability that they will be contested, experts say.

In Mathare, the Luo community says it has seen signs of Kenyatta’s ethnic patronage network in the slum for years. A national youth employment program, for example, exists only on the Kikuyu side of the bridge. Mathare’s wealth — and particularly its real estate — remains mostly in Kikuyu hands. Kenya has 42 official tribes, and several of them have members in Mathare, but the Luo and Kikuyu are the most prevalent.

Across Kenya, the Kikuyu make up roughly 22 percent of the country and the Luo make up about 13 percent. Kenyatta and Odinga have formed coalitions with other major tribes. Those tribal identities were sharpened during Britain’s colonial reign, when colonizers used a strategy of “divide and rule” to keep tribes from uniting in opposition. In recent years, a class of urban, educated Kenyans has emerged, less interested in a politics dominated by tribe, but that demographic remains a minority.

In 2013, when the official results said that Odinga lost to Kenyatta by seven percentage points, Odinga launched a failing appeal in court, alleging a rigged outcome. This year, Odinga has indicated that he’ll take a bolder stand if he suspects fraud.

In January, he told reporters, “We are not going to take it lying down” if they suspect vote rigging.

In Mathare, some of his supporters have suggested that an Odinga loss would translate into immediate violence.

“If he loses, Kenya will burn,” said Nicholas, the lab technician, who didn’t want to specify what role he might play in such a display.

But standing about 20 yards from Mathare’s bridge, his expression grew more serious.

“I will need people to know that I am not content.”

Rael Ombuor contributed to this report.