Mr. Smith went to Washington. Now, Mr. Castillo has come to Lima.

The rise of Pedro Castillo, a previously obscure leader of a rural teachers union, to Peru’s highest office is the most glaring example yet of the power of the pandemic to upend politics in Latin America.

The ravages of the coronavirus, and the surges in poverty and inequality it has caused, have provoked nearly 1 million people to protest in Colombia and saw a communist elected mayor of Santiago, the capital of Chile, the region’s free-market model.

In Peru, a what-more-have-we-got-to-lose mentality helped propel one of the most unusual candidates ever to win a Latin American presidency. A 51-year-old, straw-hat-wearing schoolteacher and farmer who reported an income last year of $16,600, Castillo had never held public office.

On Wednesday, he assumed the nation’s highest one. Wearing his trademark straw hat and a traditional suit with a collar woven in an Indigenous pattern, Castillo placed his hand on the Bible and pledged to fulfill his mission as president and deliver a country “without corruption and with a new constitution.”

In an address to Congress, he celebrated Peru’s Indigenous peoples and blamed the Spanish conquest and the legacy of colonialism for the inequalities that persist in the nation today.

“This is the first time that our country will be ruled by a peasant,” he said. “Someone who belongs to those who have been oppressed for so many centuries. It is difficult to express what a high honor this is for me. The pride and pain of our country runs through my veins.”

He outlined a vision for a much-changed country — one where attending universities would be free, but unemployed youth who were not in school would be conscripted by a military redeployed for engineering and public works projects. Indigenous languages would be used inside government offices and by state officials in parts of the country where they predominate. Immigrants who commit crimes, he said, would be summarily deported within 72 hours.

The priority for his new government, he said, will be coronavirus vaccinations, access to health care, economic revitalization, improving education and aiding the rural poor.

He sought to temper fears that his government would enact a series of far-left policies including nationalizations and land seizures, saying property rights would be guaranteed. “We will do none of that,” he said.

At the same time, however, he pledged to target “monopolies” that have driven up prices for everything from gasoline to medicines, and suggested the state might intervene in some sectors “to reduce costs.” He put on notice the foreign investors who he suggested had negotiated overly generous contracts with past governments to extract Peru’s natural resources.

“The state must have the freedom to promote, to monitor and regulate according to the interests of the majority,” he said.

He vowed to rapidly create 1 million new jobs, at least some of them temporary, through public works projects and other state employment. The rural teacher also promised to declare a national “emergency” over the need for improved education. He said he would beef up agricultural production, “clean up” the all-important mining sector and attack the “cancer of corruption.”

And he promised to enshrine a country “for the people” in a new constitution, with the input of Indigenous groups, Afro-Peruvians and labor unions.

In a highly symbolic act, he said he would not reside in Lima’s ornate Government Palace — also known as the “House of Pizarro” after Francisco Pizarro, the Spanish conquistador who built the original structure and ruled there for the Spanish crown in the 16th century.

“I will not rule from Pizarro’s house, because I believe that we have to break with colonial symbols to end the ties of domination,” Castillo said. “We will cede this palace to the new ministry of culture, so that it can be used as a museum that shows our history.”

Yet he faces a number of challenges from the start, including a struggle within his inner circle for influential positions within a cabinet he has yet to announce. He confronts a hostile, fractured Congress run by his political enemies, with a history of impeaching presidents.

Television commentators on Wednesday denounced a wave of “racist” vitriol circulating on social media against Castillo, who has described himself as a “campesino” — a member of the largely Indigenous and mixed-race rural farming class.

The inauguration attracted leaders from across the region, including right-wing presidents Sebastián Piñera of Chile and Iván Duque of Colombia, who sought to sidestep suggestions of ideological differences with the leftist Castillo.

“We come to reaffirm the brotherhood between our two countries,” Duque told journalists outside the Foreign Ministry, where Castillo was meeting with heads of state.

By taking the helm in Lima, Castillo is going from nurturing poor children in a multi-grade classroom to handling the weightiest matters of state — including his pledges to rewrite the constitution and force a reckoning with foreign mining interests.

In a race that pitted Peru’s elites against a man they derided as a country bumpkin unfit to rule, Castillo edged out the right-wing political veteran Keiko Fujimori, the daughter of jailed former president Alberto Fujimori. After losing a six-week effort to challenge the results, the Peruvian right is now gnashing its collective teeth, warning of a communist wolf in peasants’ clothing who they say will turn Peru into socialist Venezuela.

Some members of Castillo’s Marxist-Leninist party, Free Peru, have called for the expulsion of the U.S. military and the Drug Enforcement Administration, as well as a broad legalization of coca, the leaf that is the building block of cocaine. The party defines itself as a group of leftist thinkers who embrace “Marxist theory, using its light to interpret all phenomena that occurs in world.”

His opponents wince at the idea of Castillo taking power.

Pedro Arturo Cerna, a lawyer and small-business owner who, like Castillo, is originally from Cajamarca, predicted national devastation.

“I do not think he has the capacity or education to lead a country,” Cerna said. “He does not understand economics, taxes or basic issues of governing. He will be a puppet, not only of his party, but also Cuba and Venezuela. They are the ones running the show.”

Castillo largely avoided detailing his economic platform during the campaign. After the election, he pushed back against fears of a radical left rising in a country that was terrorized by leftist guerrilla movements in the 1980s and 1990s.

“We are not communists,” he told a crowd of supporters last month. “We are not about destabilizing the country. We are workers, fighters, entrepreneurs and we will guarantee a stable economy.”

Castillo, who went from tied for last in the polls among 18 candidates in January to winning the presidency in June, has sought to portray himself as more moderate than his party, while offering very few clues as to what he might actually do in Lima, a swamp he has pledged to drain.

He has vowed to insert the state more deeply into the country’s lucrative mining sector, but has not explained when, how or to what extent. He is a social conservative who has opposed same-sex marriage but tried to focus his candidacy more on the nation’s economic plight, with pledges to fight the pandemic, poverty and unemployment.

His largely poor and lower-middle-class supporters, meanwhile, are applauding the success of one of their own, a symbol of hope in the face of soaring poverty amid the pandemic, as well as what many in Peru see as a corrupt political class.

Peru has had four presidents in five years. Two were forced out amid corruption allegations, and another over the use of excessive force against protesters. More than 50 lawmakers in the 130-member legislature are under investigation or facing criminal charges. Keiko Fujimori has been in and out of jail in the past two years amid allegations of money laundering and campaign finance violations.

“There is no precedent in Latin America of someone coming from nowhere to shake the establishment and reach the presidency like Pedro Castillo,” said Michael Shifter, president of the Washington-based Inter-American Dialogue. “Castillo’s eloquent cry for social justice [that] resonated in a country ravaged by the pandemic, and whose leaders have proved to be corrupt and irresponsible, [allowed] Castillo to tap into the nation’s cumulative popular resentments and grievances.”

Castillo’s background, from outside the country’s elite, brought issues of class to the surface in a hard-fought campaign.

“I know it doesn’t sound very democratic, but could we ban the rural vote in the runoff,” one Twitter user posted before the second round. Another said the “only ones responsible for these results are the Quispes and Mamanis,” a reference to the most common Indigenous surnames in the country.

Castillo ran for mayor of Anguía, a tiny, poor town in Cajamarca, in 2002 and lost. He continued teaching at his school in the highland district where he was born. He was also the school cook and janitor.

He came to national attention four years ago when he and other rural teachers called a strike, rebelling against a national union they said had failed to represent them. By August 2017, they had closed down schools in parts of the country and forced a cabinet reshuffle.

Castillo returned to his classroom but had acquired a taste for politics. He tried unsuccessfully to set up a political party for teachers. Then, last year, he accepted an invitation to be the long-shot presidential candidate for Free Peru, after its founder, Vladimir Cerrón, found guilty on corruption charges, was banned from holding public office.

Castillo was initially written off as a serious candidate. He was polling at less than 1 percent as recently as January but took off as the front-runners appeared unconvincing on the campaign trail. In debates, Castillo connected with voters in the Peruvian countryside on the back of his everyman credentials as a schoolteacher. He finished first in the first round of voting in April with close to 19 percent of the vote.

“He understands the value of work and honesty,” said Roy Vilcayauri, a rural development adviser in the countryside outside Lima, who voted for Castillo. “He will lead a government based on transparency, something we are not used to in Peru.”

Yet his election produced as much fear as hope. Secretary of State Antony Blinken congratulated Castillo after he was declared winner. Privately, U.S. officials have expressed concern about the anti-American sentiments that pervade his party.

Carlos Herrera, the two-time minister of energy and mines who now heads Peru’s engineering society, warned that any unilateral move by Castillo to nationalize resources or eliminate tax agreements with foreign mining companies would lead to international arbitration against the country at a time when prices for its commodities — such as copper — are soaring.

Castillo’s call for nationalization of resources is “more passion than logic,” Herrera said. “Any abrupt move could slow or stop exploration and investment, which are essential.”

Gonzalo Alegria, a banker advising Castillo, said Herrera and others predicting doom have nothing to worry about. He said Castillo would not be making radical moves, but changes to grow the economy sustainably.

“The central bank will remain independent,” he said. “No one is going after bank accounts or pension funds or confiscating property. Critics are creating a crisis without listening to what he has to say.”

Read more: