In 2009, when Rio de Janeiro won the right to host the 2016 Olympic Games — beating out Madrid, Tokyo and Chicago — Brazil was flying high. Although it had not escaped the consequences of the 2008 financial crisis, it had suffered less economic damage, and come back more quickly, than other countries, including the United States.

With the economy booming, the federal government felt so flush that its popular president, Luiz Inácio Lula da Silva, had instituted a series of expensive social programs that helped push millions of poor Brazilians toward a better life. The Economist magazine predicted that Brazil would soon be the world’s fifth-largest economy, leapfrogging Britain and France.

“I’ve never felt more pride in Brazil,” Lula (as everyone in Brazil calls him) said after Rio’s bid victory was announced. “Now, we are going to show the world we can be a great country.” He wasn’t the only one who felt that way. On Copacabana Beach in Rio, a huge party broke out.

A municipal health worker sprayed insecticide in February to kill mosquitoes in Campina Grande, Brazil. Concerns about the Zika virus have led some athletes to refuse to attend the Rio Games.

The Games begin in six weeks, but nobody is partying anymore. The economic — and social, and political — conditions facing Brazil and Rio have changed drastically. A huge corruption scandal that began at the country’s giant oil company, Petrobras, resulted in exposés and investigations into dozens, if not hundreds, of high-ranking politicians and members of the business elite. Lula’s handpicked successor, Dilma Rousseff, is being impeached for covering gaps in the government’s budget in ways that were allegedly illegal. (She has never been connected to the larger scandal, however, despite having once been the chairwoman of Petrobras.) Lula himself is under investigation.

The country’s economy has also fallen off a cliff, its gross domestic product dropping by 3.8 percent last year alone. Both the state of Rio de Janeiro and the city are broke — and the federal government is not in great shape, either. Teachers and the police have had their paychecks delayed. Those much-praised social programs have been cut back. Inflation is on the rise. So is crime. The state security budget has been cut. Just days ago, armed men attacked Rio’s largest public hospital, successfully freeing a drug kingpin. Plus there’s the Zika virus, which has hit Brazil hard. According to the International Monetary Fund, Brazil’s economy has slipped to ninth in the world, behind not only Britain and France, but also India and Italy.

Are the Olympics responsible for those problems? Of course not. But they’ve highlighted them. Whereas winning the Olympics in 2009 seemed to symbolize Brazil’s new place on the world stage, the Olympics have since come to represent something else: “the hubris that existed during the boom years under Lula,” said Alex Cuadros, the author of “Brazillionaires,” a book about Brazil due out in July. And at this point, Rio’s problems and the Olympics’ problems seem intertwined.

Supporters of Brazil’s suspended president, Dilma Rousseff, protesting at a June rally in Rio de Janeiro against Michel Temer, the interim president. Political tensions are rising in the lead-up to the Summer Games.

In April, a top state official, Leonardo Espindola, publicly acknowledged that Brazil’s problems could affect the Olympics and damage the country’s image. “We are nearing a social collapse in our state,” he said.

Cities that hold Olympics rarely, if ever, break even on the Games. In Rio’s case, it won’t even be close. Brazil originally budgeted more than $14 billion to hold the Olympics, money that would be spent on infrastructure — stadiums, transportation improvements, the Olympic Village and so on — as well as on security and other logistical requirements.

That number is now estimated at about $20 billion. But Rio is only likely to reap, at most, $4.5 billion in revenue, said Andrew Zimbalist, a sports economist at Smith College whose recent book, “Circus Maximus,” examines the economic consequences of the Olympics and the World Cup.

Workers erecting scaffolding in June to repair a bike lane that was destroyed by a wave in April, leaving two people dead in Rio de Janeiro. The project was heralded as one of Brazil’s infrastructure improvements before the 2016 Olympics.

Instead, what cities promote when they bid for the Olympics are two things. The first is tourism: The Olympic Games, carried on television all over the world, offer a city publicity like almost nothing else. Barcelona and Sydney are great examples of cities that became much more prominent as tourist destinations after they held the Summer Games, in 1992 and 2000.

Second, cities claim that the infrastructure and improvements that are made to accommodate the Games will improve residents’ lives long after the athletes have left. As part of its bid, Brazilian officials promised to clean up the notoriously polluted Guanabara Bay in central Rio, where the sailing competition will be held. They would build stadiums, yes, but also infrastructure that would ease Rio’s congested traffic. Officials also said that the Olympics would improve tax revenue and economic growth — not only in the years before the Games, but for years afterward.

It may turn out that the Rio Olympics will increase tourism, but the bad publicity surrounding Rio’s preparation for the Games makes that a dubious proposition. As has been widely reported, the bay remains polluted, with the government having essentially given up on cleaning it up; it simply doesn’t have the money. Thousands of people who live in favelas — Rio’s notorious slums — have been ousted from their homes, often relocated hours from their schools and jobs, to make way for the needs of the Olympics. But all that Olympic construction has not been enough to stem the decline of Rio’s economy.

Sewage runoff staining Guanabara Bay, which will hold the sailing competitions at the Rio Olympics. Brown water, foul odors and floating trash are still marring the rivers, beaches and lagoons around the city.

Perhaps the best example of the problem with Rio’s Olympic-mandated infrastructure is a new 10-mile rail line that will connect the hotels of Ipanema and Copacabana to the western suburb of Barra da Tijuca, where the Olympic Park has been built. It will cut the travel time from over an hour by car — on a good day — to less than 30 minutes. But after many delays, the rail line is now expected to open just four days before the opening ceremony. The cost has risen to $2.8 billion after an initial estimate of $1.6 billion. There are serious questions about whether there will be enough time to properly test the new line before putting it into use.

There is also a question about how useful this new line will be after the Games. Barra da Tijuca is a relatively wealthy area, and the most urgent transportation needs are in poorer areas of Rio. “The building of the new subway line is problematic,” said Christopher Gaffney, a professor at the University of Zurich who studies large-scale sports events like the Olympics. “Extending that line meant they couldn’t afford to extend any other line where it was really needed. It is a poorly conceived, poorly executed project.”

At this point, virtually all the problems troubling the country seem to be reflected in Rio’s Olympic preparation. Corruption? Prosecutors are investigating a number of construction companies building the Olympic sites, starting with Odebrecht, which is involved in over half the Olympic projects. Zika? The virus has caused some public health officials to call for the Games to be canceled, and a handful of athletes — the golfer Rory McIlroy, most recently — have declined to participate. Zika is the ultimate in bad publicity. Lack of money? The Brazilian organizers have had to cut about $500 million from the Olympic budget — affecting aspects of the Games including the opening and closing ceremonies (they’re being pared back) to the athletes’ dorm rooms, which won’t have televisions (the organizers were going to charge the athletes for air-conditioning but backed down).

There have been other miscues, too. In April, a bike path that had been built next to the ocean as part of the Games’ infrastructure improvements collapsed, killing two people on the same day the Olympic torch was lit in Greece. (More bad news came Friday, when the World Anti-Doping Agency suspended the accreditation of a Rio lab that had been renovated, at great expense, to handle drug testing for the Games.)

Last week, the governor of the state of Rio de Janeiro declared a state of “public calamity” — a declaration usually associated with a natural disaster — essentially acknowledging that the state was bankrupt and would be unable to honor its commitment to the Olympics without help. The federal government stepped in with an emergency $850 million loan, some of which will be used to complete the new rail line.

The Games will go on, of course, and for those of us watching on television, it will be a splendid spectacle. Most of the Olympics will take place in a kind of bubble, divorced from the city’s problems. But after the Games end on Aug. 21, almost three weeks after they begin, most of us will move on. The people of Rio will be left to pick up the pieces.