LAST year Paulo Rezende, a Brazilian private-equity investor, and two partners decided to set up a fund investing in suppliers to oil and gas companies. Although this industry is centred on Rio de Janeiro, Brazil's second-largest city, with its huge offshore oilfields—and fabulous beaches, dramatic scenery and outdoor lifestyle—they instead established the Brasil Oil and Gas Fund 430km (270 miles) away, in São Paulo's concrete sprawl. Even though it means flying to Rio once or twice a week, Mr Rezende, like many other businesspeople, decided that São Paulo's economic heft outweighed Rio's charms. But the choice is harder than it used to be.

For many years, São Paulo has been the place for multinationals to open a Brazil office. It may be less glamorous than Rio, as the two cities' nicknames suggest: Rio is Cidade Maravilhosa (the Marvellous City); São Paulo is Cidade da Garoa (the City of Drizzle). But as Mr Rezende sadly concluded: “São Paulo is the financial centre, and that's where the money is.”

Edilson Camara of Egon Zehnder International, an executive-search firm, does 12 searches in São Paulo for each one in Rio. The biggest mistake, he reckons, is for firms to let future expatriates visit Rio at all. “They are seduced by the scenery and lifestyle, and it's a move they can sell to their families. But many have ended up moving their office to São Paulo a couple of years later, with all the upheaval that entails.”

From a hamlet founded by Jesuit missionaries in 1554, São Paulo grew on coffee in the 19th century, industry in the first half of the 20th—and then on the misfortunes of Rio, once Brazil's capital and its richest, biggest city. The federal government abandoned Rio for the newly built Brasília in 1960, starting a half-century of decline. Misgoverned by politicians and fought over by drug gangs and corrupt police, Rio became dangerous, even by Brazilian standards. The exodus gained pace as businesses and the rich fled, mostly for São Paulo.

Now, though, there are signs that the cost-benefit calculation is shifting. São Paulo's economy has done well in Brazil's recent boom years and it is still much bigger, but Rio's is growing faster, boosted by oil discoveries and winning its bid to host the 2016 Olympics (see table). Last year Rio received $7.3 billion in foreign direct investment—seven times more than the year before, and more than twice as much as São Paulo. Prime office rents in Rio are now higher than anywhere else in the Americas, north or south, according to Cushman and Wakefield, a property consultancy.

Community-policing projects are taming its infamous favelas, or shantytowns: its murder rate, though still very high at 26 per 100,000 people per year (2.5 times São Paulo's), is at last falling. Brazil's soaring real is pricing expats paid in foreign currencies out of São Paulo's classy restaurants and shopping malls; Rio's recipe of sun, sea and samba is still free. Even Hollywood seems to be on Rio's side: an eponymous animation, with its lush depictions of rainforest and carnival, is one of the year's highest-grossing films. Rio's mayor, Eduardo Paes, has big plans for capitalising on the city's magic moment. He has set up a business-development agency, Rio Negócios, to market the city, help businesspeople find investment opportunities, and advise on paperwork and tax breaks. It concentrates on sectors where it reckons Rio has an edge: tourism, energy, infrastructure and creative industries such as fashion and film. “A couple of years ago, foreign businessmen would come to Rio and ask what we had to offer,” says Mr Paes. “We had no answer. Now we roll out the red carpet.” The political balance between the two cities has changed too. In the 1990s São Paulo was more influential and better run: it is the stronghold of the Party of Brazilian Social Democracy (PSDB), the national party of government from 1995 to 2002. Now the PSDB is in its third term of opposition in Brasília, and though it still governs São Paulo state, it is weakened by internal feuds. In Rio, by contrast, the political stars are aligned. The state governor, Sérgio Cabral, campaigned tirelessly for the current president, Dilma Rousseff—and received his reward when police actions in an unruly favela late last year were backed up by federal forces. São Paulo's socioeconomic segregation, long part of its appeal to expats, is starting to look like less of an advantage. Most of its nicer bits are clustered together, allowing rich paulistanos to ignore the vast favelas on the periphery. In Rio, selective blindness is harder with favelas perched on hilltops overlooking all the best neighbourhoods. But proximity seems to be teaching well-off cariocas that abandonment is no solution for poverty and violence. Community policing and urban-renewal schemes are bringing safety and public services. Chapéu Mangueira and Babilônia, twin favelas a 20-minute uphill scramble from Copacabana beach, are being rebuilt, with a clinic, nursery and a 24-hour police presence. The price of nearby apartments has soared. Other slums are also getting similar make-overs.

Rio's Olympic preparations include extending its metro and building lots of dedicated bus lanes, including one linking the international airport to the city centre. By 2016, predicts City Hall, half of all journeys in the city will be by high-quality public transport, up from 16% today. São Paulo's metro extensions are years behind schedule, and the city is grinding towards gridlock. Its plans to link the city centre to its main international airport (recently voted Latin America's most-hated by business travellers) rely on a grandiose federal high-speed train project, bidding for which was recently postponed for the third time.

Rio is still unpredictably dangerous, and decades of poor infrastructure maintenance have left their mark. Its mobile-phone and electricity networks are outage-prone; the língua negra (“black tongue”, a sudden overflow of water and sewage) is a staple of the rainy season; exploding manholes, caused by subterranean gas leaks, are a hazard all year round. All in all, still not an easy choice for a multinational—but it is no longer foolish to let prospective expats fly down to Rio to take a look.