By SIMON ROMERO
Horndiplomat-The Summer Olympics, fraught with financial and political difficulties, began at the Maracanã stadium in Rio de Janeiro. Credit Doug Mills/The New York Times
RIO DE JANEIRO — If there was a nation in need of an uplifting spectacle at this moment, even in the form of a public relations exercise, it was Brazil.
The first South American country to host the Olympics is reeling frozen an astonishing combination of political upheaval and economic unrest. Its efforts to stage the world’s biggest sporting event met trouble at every turn, from the Zika virus to polluted waters to budget cuts so deep that basic operations became strained.
So the opening ceremony of the Summer Games arrived Friday night as a salve, disguising the wounds for a few hours and letting Brazilians celebrate everything from the waves of immigrants still putting down stakes here to Alberto Santos Dumont, the aristocratic bon vivant whom Brazilians credit with inventing the airplane.
Over the past several Olympic cycles, the gigantic cost of hosting the Games has drawn as much attention as the athletic performances. Host countries like China and Russia have used the Olympics as a show of force. The vibe, and the budget, are different here. These are a no-frills, budget-conscious Olympics — even if the opening ceremony dazzled.
The organizers of the ceremony even chose a word in Portuguese, gambiarra, to describe their own efforts to put on a show amid Rio’s pared-down Olympic ambitions. Translating the word, which is pronounced GAHM-beeah-hah, offers its own challenges, so they offered a few options: jerry-rig, quick fix, do a MacGyver.
The Games have even been marred by scandal emanating from half a world away: nearly third of Russia’s Olympic delegation was barred from the Rio Olympics after revelations emerged of a state-sponsored doping program. Russia’s delegation on Friday night was severely depleted.
Extolling achievements like Rio’s pioneering replanting of its urban forests and the tolerance, however fragile, that characterizes much of Brazilian society, a message emanated from the opening ceremony: Some order and progress, the words optimistically emblazoned on the country’s flag, might just emerge from the creative chaos that persists here.
Pointing to the ceremony’s honoring of Brazil’s achievements as a racially diverse nation and its call for action to combat global warming, Fernando Meirelles, the director of “City of God” — about Rio’s favelas, the gritty urban areas that largely formed as squatter settlements — and one of the event’s creative directors, proudly proclaimed that it would rankle conservative figures at home and abroad.
Political leaders certainly hope that the Olympics will be a turning point in the fortunes of Brazil and Rio, whose quest to host the Olympics began in the early 1990s — a time when the city was wallowing in crisis, enduring a long decline after authorities built Brasília, the new capital, from scratch deep in the country’s interior and transferred much of the federal bureaucracy there in the 1960s.
Still, the International Olympic Committee frequently frustrated Rio’s ambitions. It was only in 2009, when Brazil’s star was on the rise as the economy prospered from a commodities boom, that Rio was finally awarded the Games. Elated crowds celebrated on the sands of Copacabana.
“I’ve never felt more pride in Brazil,” Luiz Inácio Lula da Silva, the country’s president at the time, said when Rio got the Games. “Now, we are going to show the world we can be a great country.”
But much has changed since that exuberant day. Brazil’s economy is mired in its worst recession in decades. Rio is grappling with resurgent violent crime. And colossal corruption scandals are casting a pall over the nation’s political establishment.
The city’s preparations for the Olympics were marked by a long string of fiascos, including the recent collapse of an oceanfront bicycle path that killed two men. Mr. da Silva, universally known as Lula, did not even attend the opening ceremony — he is instead preparing for a trial on charges that he tried to obstruct an inquiry into a massive bribery scheme at Petrobras, the national oil company.
Mr. da Silva’s protégée and successor, Dilma Rousseff, who was suspended as president to face an impeachment trial, also skipped the show. Instead, it was the interim president, Michel Temer — who had emerged victorious in a power struggle in May — who was in attendance.
“We Brazilians can say with pride that we are one of the most mixed-race countries of the world,” Mr. Temer said in an essay published on Friday. Still, he left unsaid how he named a cabinet without any Afro-Brazilians or women, making him a target of scorn in much of the country.
Without delving explicitly into politics, the ceremony explored Brazil’s complex history, including its settling by indigenous peoples, its colonization by Portuguese explorers and the tragic scope of the country’s slave trade.
About 51 percent of the population define themselves as black or mixed race, according to the 2010 census. The scale of Brazil’s slave trade is hard to fathom. The country received about 4.9 million slaves through the Atlantic trade, compared with mainland North America’s importation of 389,000, according to the Trans-Atlantic Slave Trade Database.
Rio, a city without a major slavery museum, is still grappling with how to discuss the ways the slave trade affected its development — even though it received more than 1.8 million African slaves, more than any other city in the Americas. Rio alone accounted for about 21.5 percent of all slaves who landed in the Western Hemisphere.
In an interview, the rapper Karol Conka said that she had directed her performance at Mr. Temer, the broadly unpopular interim president, and Jair Bolsonaro, an ultraconservative congressman with rising political clout who talks with revulsion about Haitian immigrants to Brazil and defends the torture of drug traffickers.
“They need to understand what empathy is,” said Ms. Conka, 29, who is from the southern city of Curitiba. “The current political moment in Brazil is just unpleasant. Slavery might not exist anymore but blacks in our society are still undervalued and attacked on social media. The only way to help the new generation is with education.”
Reflecting, perhaps, the resilience of freedom of expression in Brazil’s unruly democracy, some observers voiced displeasure over the lavish ceremony.
Letícia Bahia, a psychologist and feminist commentator, questioned the prominence given to Gisele Bundchen, the Brazilian supermodel who catwalked to the sounds of the song “Girl from Ipanema.”
“What does it say about a mixed-race country, boasting about its pride over miscegenation, to choose a supermodel who is white, ultra skinny, blonde and blue-eyed to represent the women of Brazil?” Ms. Bahia said.
Alvaro Siviero, a Brazilian classical pianist and music critic, compared the ceremony to Russia’s in 2014 for the Winter Olympics in Sochi, where literary giants like Gogol, Tolstoy and Nabokov were celebrated.
Why not shine a light on Heitor Villa-Lobos, the prolific Brazilian composer of the 20th century, Mr. Sivieiro asked. Or Machado de Assis, arguably the greatest writer of Brazilian literature.
Various stunning musical performances marked the extravaganza, with a new generation of performers like MC Soffia, a 12-year-old rapper from São Paulo’s hardscrabble periphery.
In one of the ceremony’s more thrilling moments, dancers representing the Bate-Bolas, a raucous Carnival tradition in Rio, enacted a clash with others representing Maracatu, another Carnival tradition from Pernambuco in northeast Brazil drawing on African and indigenous influences.
On a more cerebral note, the actors Fernanda Montenegro and Judi Dench read from “Nausea and the Flower,” a 1945 poem by Carlos Drummond de Andrade, in which the poet complained about an array of problems: “It’s still a time of feces, bad poems, hallucinations, and waiting.”
And yet, the poet manages to find hope in a flower sprouting through the asphalt.
Building on that thought, the ceremony issued a call to action to combat global warming, putting forward the strategy of reforestation to capture carbon. Curiously absent from all of this was any mention of Petrobras, the national oil company that ranks among the world’s largest petroleum concerns.
Its huge oil discoveries turbocharged Brazil’s economy, enabling the country to project clout whenit was awarded the Olympics. Now Petrobras, a major emitter of greenhouse gases, is mired in scandal following revelations that Brazil’s leaders used the energy behemoth to fund their political campaign.
On Saturday, the Games begin in earnest. Will the athletes fully command the spotlight, or will the host’s nagging problems mount? The world is watching.
A version of this article appears in print on August 6, 2016, on page A1 of the New York edition with the headline: World Begins Gilded Games In Gritty Rio.