Workers were cementing the last paving slab in place and sweeping off debris as I arrived at Paseo Yugoslavo, a pedestrian-only walkway high above the Chilean port of Valparaíso. Strolling locals once favoured this nook of Cerro Alegre, the city’s prettiest hillside, but urban decay had taken its toll, the serpentine streets turned scruffy and soulless, the once-splendid mansions left to rot.

Now, as I sat beneath a pepper tree in a tiny plaza, I took in the signs of renewal and rebirth. To my left, the first guests were arriving at the Hotel Palacio Astoreca, its palatial stucco-and-brick exterior newly washed in a startling, pillar-box red.

Fresh paint in kaleidoscopic shades was evident, too, on the quaint clapboard houses that climbed steeply up the hill, where recently installed street lamps would soon cast a warming glow. Not a single scrap of rubbish fluttered in the breeze.

To my right, where its ornamented towers and green copper roof made the Palacio Baburizza the most noticeable building on the hill, a work crew was removing hoardings from its art nouveau façade. “They’d better hurry,” grunted a passer-by, as hired hands scrubbed the last graffiti from its red-and-white chequered walls. “The president’s coming to open the palace next week.”

Chilean president Sebastian Piñera did indeed visit Valparaíso on September 28 to mark the reopening of the Palacio Baburizza and the fine arts museum it contains. After a 15-year hiatus, the museum’s renovation represents a huge leap for Chile’s most distinctive city yet one of its most troubled. Closed in 1997 for repairs that were never carried out, the palace slid gracelessly into dereliction, its ruin becoming a symbol of the city’s wider malaise. Now, after a six-year beautification campaign that included the museum’s complete renewal, a city abandoned by most Chileans is set to recapture some of its glorious past.

By rights, Valparaíso should be one of Chile’s must-see destinations. Just 90 minutes from the capital Santiago, the Unesco World Heritage site and one-time home to poet Pablo Neruda boasts a rugged, quirky beauty and a compelling history.

As a stopover for ships sailing from Europe to California via the Magellan Straits in the 19th century, Valparaíso boasted Chile’s first stock exchange, first public library and oldest professional soccer team. Its local newspaper, El Mercurio de Valparaíso, was founded in 1827, making it the country’s oldest, and the world’s oldest Spanish-language newspaper still in print (Peru’s El Peruano was founded two years earlier but has had several name changes).

Straddling a series of hillsides that form a natural amphitheatre along the Pacific coastline, its cobbled streets twist sharply upwards from a narrow waterfront strip, scaling gulleys and ravines towards the higher mountains behind. In places, the ravines are so steep that footpaths resemble staircases; in others, they give way entirely to diminutive funicular railways, or ascensores, whose tiny wooden cabins and clanking, British-built machinery were constructed a century ago.

Despite such obvious charms, Valparaíso has spent much of the past century in disarray. The opening of the Panama Canal in 1914 killed the shipping trade; more recently, chronic underfunding and poor political leadership fostered a pervasive culture of decline. Tourists snubbed the city en masse, preferring beach resorts to the north like Viña del Mar or Reñaca. The middle classes, too, began drifting away, taking their spending power and tax contributions with them, along with a sizeable chunk of the local economy. “The emptying of the city has left it depressed for 30 years,” the mayor, Jorge Castro, told me. “While the rest of Chile moved on, Valparaíso declined.”

In their place, its picturesque alleys filled with drug addicts, stray dogs and trash. Its mansions were abandoned, damaged by earthquakes, or destroyed by one of the highest arson rates in the country. A notable waterfront building, Edificio Luis Cousiño, was even known as La Ratonera (the rat trap) to the addicts who both squatted in it and set fire to it for years. Racked by fire, seismic tremors and neglect, Valparaíso became a luckless Gomorrah, “a city of tragedy”, as one theatre director told me.

Murals decorate the walls

And the decline of Baburizza’s palace was the most tragic element of all. Built by Italian architects in 1916 in a glorious cacophony of styles, the mansion was named by Pascual Baburizza, a Croatia-born minerals magnate who struck it rich in Chile and used the mansion to hang the oil paintings he shipped in by the dozen from European auction houses. In 1971, the Valparaíso municipality bought the house. Plagued by underfunding and poor upkeep, however, the building deteriorated, its decline exacerbated by botched repairs. Successive mayors failed to find funds for renovation. Rain poured through the roof, graffiti spread further up the red-and-white chequered walls, and termites began feasting on the carved wooden lintels within. “The house was a disaster,” Carlos Lastarria, the museum’s curator, told me. “The mud covering the ground floor was nearly a metre deep.”

By the new millennium, the museum’s demise – and Valparaíso’s wider decay – had become a national embarrassment. After Unesco named Valparaíso’s oldest districts a World Heritage site in 2003, Chile’s then-president Ricardo Lagos outlined a US$73m project, partly funded by the Inter-American Development Bank, to overcome the city’s worst ills.

The Valparaíso Recovery and Urban Development Programme’s primary goal was to buy and restore heritage buildings, but its remit also strayed into more controversial areas: street lighting, rubbish collection and the sterilisation of some 18,000 stray dogs. Local authorities were left largely out of the loop. “In addition to its immediate goals, the programme was purposely designed to outlast any single government administration,” said Roberto Barría, the project’s director. “It’s been an excellent initiative for Chile.”

Now, as the wrappers come off some of Valparaíso’s most iconic buildings, the city seems able to breathe once more. Valparaíso is still no anodyne tourist village: its grit and soul remain intact. But the shoddiest ascensores have now been refitted. La Ratonera, beautifully restored, now houses a university library. The Chilean navy, too, has revamped its excellent museum, expanding the collection and relaunching it as the National Maritime Museum.

Even the city’s former prison, once squatted by an artists’ collective, has reopened as Parque Cultural de Valparaíso, a spectacular $20m cultural centre, with state-of-the-art rehearsal, recording and performance spaces for dance, music and theatre acts.

Moreover, public spending has encouraged private investment. In quaint Cerro Concepción, shingle-walled antique stores and artists’ studios are still held together with wire and generous doses of luck, but window frames, lintels and façades are freshly painted, the once-rusted roofs given a fresh coat of red oxide.

The terrace of a suite at Palacio Astoreca

In Cerro Alegre, a Swiss-Chilean couple spent $5m restoring the Palacio Astoreca, renovating its porticos, projections and pitched roofs and recreating its interior plasterwork in fastidious detail. “The building was consumed by termites,” said manager Bernardo Vogt, as he welcomed a group of curious locals keen to assess the renovation. “The transformation was incredible.”

Even residents of less salubrious districts like Barrio Puerto and Cerro Artillería are sprucing up their homes and clusters of loft-style apartment blocks aimed at well-to-do urban youth have sprung up. “Our projects were the first outside the districts that were seen as fashionable,” says architect Antonio Menéndez, who recently completed two apartment projects in formerly down-at-heel Cerro Yungay. “Sales have been so strong that we’re working on two more.”

Back at the Palacio Baburizza, with just days to go before the museum’s reinauguration, the curator was making last-minute adjustments to temperature and humidity. Workers had dusted the mansion’s fluted wooden fireplaces and oak parquet floor, roping off rooms made ready for the president’s visit. Even Baburizza’s original bathtub had been scrubbed, along with his brass-and-nickel all-body shower, industrially machined in the 1920s at vast expense, “a classic millionaire’s toy”, sniggered a security guard. “At the time, the water pressure on the hill wouldn’t have been enough to power the thing.”

His work nearly done, Lastarria, the curator, sat back to take stock. “This is a great time for Valparaíso, but it’s no moment for celebration,” he said. “We have finally honoured a duty to the city that was outstanding for a very long time.”