BOGOTÁ, Colombia — Given the staid nature of the political establishment in Colombia, Washington’s top ally in the region, and the broad popularity of President Álvaro Uribe, it seemed a foregone conclusion to many here that his heir apparent would clinch the presidency in the coming elections without too much of a struggle.

So imagine the surprise when Juan Manuel Santos, a former defense minister and the architect of some of Mr. Uribe’s crushing blows against leftist guerrillas, found himself trailing in recent national polls to a quirky, unpredictable mathematician who murmurs in French about arcane philosophical concepts and wears a chinstrap beard with the air of a latter-day Thoreau.

The surge of this candidate, Antanas Mockus, who served two very colorful terms as Bogotá’s mayor, has made for one of Latin America’s most exceptional presidential races in recent memory, pitting an insurgent intellectual against an establishment that suddenly finds itself on the defensive.

While Mr. Uribe is still admired after making inroads against guerrillas and overseeing a decline in crimes like murders and kidnappings, many voters are weary of the scandals involving his intelligence agency and his supporters’ ties to right-wing paramilitary groups. The specter of violence is also returning, with homicides climbing 16 percent in 2009, possibly affecting Mr. Uribe’s legacy.