Bolivian President Evo Morales shows a photograph of graffiti that reads “No more Indians” during a news conference Feb. 24, 2016, at Quemado Palace in La Paz. (Aizar Raldes/AFP/Getty Images)

Voters in Bolivia have narrowly rejected a constitutional change that would have allowed leftist Evo Morales, South America’s longest-sitting president, to run for a fourth term and potentially extend his rule to 2025.

The final tally was close, with the “no” vote winning 51 percent to 49 percent for “yes,” with 99.8 percent of votes counted as of Wednesday afternoon.

Morales acknowledged the defeat in a televised appearance Wednesday morning, assuring supporters that the “fight against capitalism and neoliberalism” would soldier on.

“We’ve lost a battle but not the war,” he said. “This isn’t the end of Evo.”

Morales, 56, has spent a decade in power, and the loss was the first electoral setback for the popular former coca grower, who is the first Bolivian president elected from the country’s long-downtrodden indigenous majority.

But even Morales was not immune to the anti-incumbent climate sweeping South America, where leftist leaders have dominated elections for more than a decade by promising to redistribute wealth and boost social spending, buoyed by strong global demand for the region’s commodity exports.

Now the party is ending, as Chinese demand for raw materials goes slack and government revenue from commodity exports is shriveling. Even the most successful South American leaders are paying a price.

Unlike Argentina and Venezuela, where entrenched leftist parties were thrown out amid deep financial troubles, Bolivia has a strong economy, projected to grow 4.5 percent this year. But after a recent spate of scandals, many Bolivians have grown weary of Morales, who took office in 2006. Voters in the region are also increasingly skeptical of attempts to remove democratic checks on power, said Michael Shifter, president of the Inter-American Dialogue, a Washington think tank specializing in Latin American affairs.

“Even Evo’s supporters, who credit him for the country’s progress in recent years, wanted to send a message that three terms in power is more than enough and it’s healthy for someone else to take charge,” Shifter said. “Bolivia under Evo may have shown some authoritarian tendencies, but it has a democratic system, and it’s natural and normal for people to want change and a fresh political environment after such a long stretch of one man in office.”

“Evo should now begin to groom a successor, but he seems to be resisting that,” Shifter added.

Morales was reelected to a third term in 2014 with 60 percent of the vote. Mixing fiery socialist speeches and denunciations of American “imperialism” with far more quiet pro-business prudence, he built roads and gas pipelines while also accumulating one of the world’s biggest cash reserves. This pleased everyone from rural Bolivian quinoa farmers to Wall Street bond ­traders.

But a wave of scandals appeared to hurt his proposed constitutional change to lift term limits. In recent months, Morales acknowledged that he had fathered a child in 2007 with a girlfriend nearly half his age.

The ex-girlfriend later got an executive job working for a Chinese company with almost $500 million in government contracts, and Morales claimed he no longer had a relationship with the woman despite appearing with her in a recent photo.

Powerful indigenous groups in the country have broken with him, too, accusing Morales of ignoring their plight, and the president was also hurt by a video last year that showed him ordering an aide to bend down and tie his shoelaces.

Morales on Wednesday accused opponents of dirty tricks, racism and a negative media campaign. He said that “the time had come” for tighter regulations on the Bolivian press.

Sunday’s ballot measure lost by just 115,000 ballots out of 5.2 million cast, and it’s possible Morales could float a similar referendum in the future, before his term expires in 2020. The region’s ­negative economic outlook does not bode well, but Shifter said ­Morales should not be underestimated.

“Hugo Chávez, too, suffered a setback in 2007 when he lost a vote to abolish term limits — only to come back later to get it passed,” Shifter said. “Evo is resourceful. He did not lose reelection — he just lost a referendum that would have allowed him to run again in 2019.”

Read more:

Evo Morales, Bolivia’s powerful incumbent, plays politics at high altitude

Scandal emerges as Bolivia president seeks fourth term

South America is staring down an economic abyss

Today's coverage from Post correspondents around the world