Over the last decade, Colombia has been a touchstone of what good design and enlightened politics can do for cities. If Barcelona was the urban exemplar of the 1990s, urbanists these days are more likely to mention Colombia's capital, Bogotá, and its second city, Medellín. In both cities, a succession of dynamic mayors has used transport infrastructure and new public buildings as tools of social change. But this tale of two cities doesn't come with two happy endings.

In Bogotá, two mayors in particular, the former philosophy professor Antanas Mockus and Enrique Peñalosa, had a dramatic impact. Famously, they brought decent sidewalks, bike lanes and the Transmilenio bus service to bypass the capital's crippling traffic – measures that privileged the non-car-owning poor. Their achievements have even been celebrated in more than one documentary. But this success story has gone awry. Today, the Transmilenio is so overcrowded even the passengers go on strike (arguably a victim of its own success); there are so many road projects underway that traffic has come to a standstill; and the last mayor, Samuel Moreno, awaits trial for corruption. "Eight years ago you believed in this city, now it's in crisis," says Giancarlo Mazzanti, Colombia's most renowned architect.

You could not say the same of Medellín, which has undergone an incredible transformation. In the 1990s, Medellín was the murder capital of the world. Then home to Pablo Escobar and the warring drug cartels, this is a city where almost everyone has a tragic story about a friend or relative. Violent crime remains a problem, especially in the poorest neighbourhoods, but nothing like in its heyday. These days Medellín is more likely to make the news for yet another photogenic building. In recent years it has kept architecture magazines drip-fed with self-consciously iconic projects of the kind that has been thin on the ground since the recession.

Mazzanti has been leading the charge. His España library-park, an outcrop of three monolithic structures, looms over the city from atop a surrounding hill. Set in one of the poorest slums, it has become an emblem of the city's renewed image as a cultured metropolis. And it is one of many. There is the even more picturesque Orquideorama, a vast hexagonal canopy structure in the botanical gardens, designed by architects Plan B and JPRCR. There is the rigorously landscaped swimming pool complex designed by a young (now disbanded) practice called Paisajes Emergentes, and the extravagantly roofed sports arena designed by Mazzanti, again, and Felipe Mesa. I visited all of these buildings last week, and though each is impressive in its own way, I do not intend to address their qualities here. Much more interesting is what they stand for – "social urbanism", as it has become known here.

Whatever one thinks about a building such as the España library – and there are those who find it less successful as an actual building than it is in terms of looks – it marks a critical shift in urban policy. For decades, cities in South America have acted as though favelas or barrios didn't exist – rarely wanting to legitimise them with transport links, electricity grids or running water, they were largely left to their own devices. This library, sitting in the middle of one as it does, makes the slums as visible as can be, and in so doing acknowledges them as part of the city proper and not some unfortunate eyesore. This is a massive U-turn since the days when it was common to speak of "cutting out the cancer" of the slums. For once, architecture-as-spectacle is not being used as a tool to market the culture industry, but to make poverty visible.

Even more significant than the library is the cable car that leads up to it from the foot of the hill, which saves residents at least an hour's climb up concrete steps. Unlikely though it is in this setting, the cable car has become a trope in South American cities, since slums often cling to steep hills where it is difficult to build roads. There is one in Caracas and one in Rio, but the first to be completed was in Medellín. Indeed, this Colombian city is a test-bed of urban innovations. There are several hybrid library-parks (part community centres and part much-needed public spaces), two cable car systems and, most recently, an outdoor escalator running nearly 400m up the troubled slum of Comuna 13.

The man who normally gets the credit for unleashing this sequence of urban interventions is, again, a mayor. Sergio Fajardo was a brilliant mathematician who was mayor of Medellín from 2003-7. He was obsessed with the idea of public space, especially in poor neighbourhoods – he attributed the fall in crime during his term in part to the increase in the amount of public space per citizen. One of these is the Parque de los Deseos, a stone plaza with fountains that doubles as an outdoor amphitheatre for film screenings. For Fajardo, good architecture and public spaces were a means of building civic pride, and the Medellín of today is a product of that vision.

However, Fajardo, the son of an architect, was merely the right man for the times – and like any politician (he is currently the governor of the state) he will happily take the credit. The real story of Medellín's transformation is rooted in a civic movement that began in the mid-90s and saw politicians, captains of industry and architects cooperating with a common goal. "The most important thing that happened in this city was not architecture but a 'social architecture' made of people – politicians and entrepreneurs understood that they had to build a future for everyone," says Jorge Perez, former head of urban planning for the metropolitan region.

Medellín developed a model that many cities around the world could learn from. For instance, the local energy company, EPM, is neither private nor nationalised but owned by the city, and it was decided that its profits (about $450m a year) should be fed back into the city. Where most mayors, including London's, have to lobby central government for money, Medellín's have tremendous spending power. Alongside this public-private partnership, the mayors have actively sought out the advice of an architecture community trained in the problems of their own city. Again, this is all too rare. In a short space of time, Medellín has turned itself into a model Latin American city, with good transport, dynamic public spaces, new schools and a culture of civic architecture. The real design project, however, was one of social organisation, with a section of society grouping together and deciding to rewrite their city's story.