RIO DE JANEIRO — Just over four months ago, Jair Bolsonaro was fighting for his life after being stabbed in the gut during a presidential campaign rally. On Tuesday, after a quick recovery and an unlikely victory, he was sworn in as Brazil’s president, steering Latin America’s largest nation far to the right in a political shift that was evident even during his inauguration.
As he addressed a crowd from the presidential palace amid unusually tight security that underscored his worry about a new assassination attempt, Mr. Bolsonaro waved a Brazilian flag and proclaimed that on that day, Brazilians were “being freed from socialism.”
The country’s flag “would never be red again,” he said, alluding to the rival Workers’ Party as he stood next to his wife and Vice President Hamilton Mourão, “even if it takes our blood to keep it green and yellow.”
The Workers’ Party, which had won the last four presidential elections, was crushed in the October vote after the country slipped into recession, violence soared and corruption scandals tarred much of the elite. It boycotted the swearing-in ceremony, reflecting the lingering bitterness of a presidential race that polarized Brazilians like none other in recent history.
Longstanding allies like Cuba, Venezuela and Nicaragua were not invited to the ceremony, in a clear signal of Brazil’s political shift. Instead, conservative governments played prominent roles as guests in the capital, Brasília — or as supporters weighing in on social media.
Shortly after Mr. Bolsonaro wrapped up his address to Congress, President Trump hailed his speech in a message on Twitter and pledged: “The U.S.A. is with you!”
Minutes later, Mr. Bolsonaro responded to the American president: “I truly appreciate your words of encouragement. Together, under God’s protection, we shall bring prosperity and progress to our people.”
The Brazilian and American presidents have similar views, temperaments and styles, increasing the likelihood of closer relations between two countries that have been uneasy allies in the past.
Stronger ties could mean more cooperation on Venezuela, where mismanagement of the economy has created a humanitarian crisis, and could put greater distance between Cuba and Brazil. The United States could also try to lean on Brazil to blunt China’s growing influence in Latin America, though, because China is Brazil’s main trading partner, Mr. Bolsonaro would have little room to maneuver, experts said.
United States Secretary of State Mike Pompeo attended the ceremony, along with Hungary’s hard-right prime minister, Viktor Orban, and Israel’s conservative leader, Benjamin Netanyahu, who said Mr. Bolsonaro had told him that moving Brazil’s embassy from Tel Aviv to Jerusalem was a matter of “when, not if.”
While his victory in October was decisive, Brazilians remain deeply divided about their new president, a former army captain who has hailed the country’s military dictators and made numerous disparaging remarks about women and minority groups.
Mr. Bolsonaro, a strident populist, rose to power by tapping anger toward the Workers Party and presenting himself as their opposite — an outsider ready to take a wrecking ball to the political establishment and, through business-friendly policies, put the world’s eighth-largest economy back on track.
During his first address to Congress, he promised to chart a bright new chapter for the country.
“Building a more just and developed nation requires doing away with practices that have been nefarious for all of us,” Mr. Bolsonaro said, shortly after he was sworn in. “Irresponsibility led us to the worst ethical, moral and economic crisis of our history.”
Mr. Bolsonaro said it would take “arduous work” to make Brazil, still recovering from a brutal recession that began in 2014, into “a strong, striving, confident and bold nation.”
While supporters in Brasília chanted “mito,” or legend, as Mr. Bolsonaro was handed the presidential band, Brazilians who opposed him spoke in apocalyptic terms about the dawning era.
“We are returning to 1964,” said Sônia Guajajara, an indigenous rights activist who ran as the vice-presidential candidate of the leftist Socialism and Liberty Party, referring to the year in which Brazil’s 21-year military regime began. “The imminent risk of a dictatorship puts us in a permanent state of alert.”
Mr. Bolsonaro’s swearing-in ended the short, tumultuous presidency of Michel Temer, who assumed power in August 2016 following the impeachment of President Dilma Rousseff of the Workers’ Party.
Mr. Temer, a center-right politician, led Brazil through a halting economic recovery. But his quest to make systemic reforms — including an overhaul of Brazil’s bloated pension system — was derailed after he was charged with corruption and obstruction of justice in 2017.
Mr. Bolsonaro takes office with a healthier economy and a significant mandate, said Monica de Bolle, a Brazilian economist who heads the Latin American Studies program at Johns Hopkins University. But she predicted that his first months in office would be turbulent, as factions within his inner circle, which includes top military figures, free-market economists and evangelical leaders, vie for supremacy.
Building support for pension reform, an unpopular measure that economists say is crucial to Brazil’s long-term economic health, will be the key test of Mr. Bolsonaro’s ability, she said.
“Over the next few months we’ll have a better idea of who’s going to be in charge within the confusion that is Bolsonaro’s inner circle,” said Ms. de Bolle, who was a vocal critic of Mr. Bolsonaro during the campaign. “I think there are a lot of question marks regarding what the priorities will be and who will be calling the shots.”
After his victory, Mr. Bolsonaro assembled a cabinet that signaled his intention to make good on his anticorruption, tough-on-crime promises and to do away with politics as usual.
Unlike former presidents, who handed out ministerial positions to members of powerful political parties in exchange for support in the legislature, he packed his government with military leaders, technocrats and ideologues, some with little or no political experience.
Mr. Bolsonaro chose several men who passed through the armed forces to form his government — including his running mate, the retired general Hamilton Mourão — a remarkable about-face for a nation that kept the military largely out of sight after the end of its rule and a transition to democracy in the mid-1980s.
He also tapped Sérgio Moro, a federal judge known for his leading role in an anticorruption investigation that led to the downfall of dozens of powerful business leaders and politicians — and landed former President Luiz Inácio Lula da Silva in prison, crushing his bid to return to power and eliminating Mr. Bolsonaro’s chief rival.
Mr. Moro’s nomination illustrated how polarized Brazil has become. Supporters welcomed it as a sign that Mr. Bolsonaro was serious about fighting corruption. But many Brazilians saw the appointment as confirmation that the judge’s conviction of Mr. da Silva in 2017, on money laundering and corruption charges, was motivated by politics.
Mr. Bolsonaro’s unorthodox choices have pleased Brazilians — 75 percent of them believe he and his team are on the right track, according to a survey by a leading polling firm, Ibope.
But turning his back on traditional parties may leave Mr. Bolsonaro and his nascent government unable to build dependable coalitions in a fractious legislature split among 30 parties.
Under pressure to deliver, Mr. Bolsonaro could focus on high-profile issues where he can effect immediate change. After running on the promise he would relax Brazil’s onerous gun ownership regulations and make it easier for the police to kill criminals, he said on Twitter that he would, by issuing an executive order, allow civilians without a criminal record to buy weapons for self-protection.
Experts said these measures might worsen violence in the country, which had a record 63,880 killings in 2017; of those 5,144 were killed by police officers. Mr. Bolsonaro’s promise to loosen gun regulations has driven more Brazilians to sign up for shooting practice at gun ranges and boosted the stock price of Taurus Armas, Brazil’s main gun manufacturer.
The president, who has proclaimed he is “homophobic, with pride,” on Tuesday vowed to shield children from “gender ideology,” a reference to teachings about sexual orientation and gender identity, which loomed large during the campaign as parents were warned that children were being exposed to inappropriate and lewd concepts.