SAN SALVADOR — President Nayib Bukele emerged as the big winner in El Salvador's legislative elections Sunday as his party and its allies took control of the national legislature at a moment when critics fear the country is sliding toward authoritarian rule.

Bukele’s meteoric rise and hardening grip on many of the country’s institutions, most notably the armed forces, have worried human rights advocates at home and abroad. His growing control could pose a challenge to President Biden’s policy of strengthening democracy in Central America — which the new administration considers critical to curbing the flow of migrants to the U.S. border.

The election could be a watershed for a country with a history of military rule that has been trying to build a democracy since the U.S.-backed war against leftist guerrillas in the 1980s.

“What’s in danger at this moment is the functioning of democratic institutions,” said Rubén Zamora, a former center-left politician and ex-ambassador to the United States.

Bukele might be the most popular leader in Latin America; 96 percent of respondents said he was doing a “good” or “very good” job in a CID Gallup survey of Salvadorans in November. His party — Nuevas Ideas, or New Ideas — did not exist when Salvadorans last voted for the Legislative Assembly, in 2018; Bukele, who was elected the following year, has been able to count on only an allied party’s 11 seats in the 84-member, single-chamber legislature.

With about 76 percent of ballots counted on Monday, Bukele’s party and a small allied party, GANA-New Ideas, had won around two-thirds of votes cast for the legislature. Salvadoran news organizations projected that would give them the 56 seats needed for a supermajority.

With that support, the president could name loyalists to key positions in the independent attorney general’s office and on the Supreme Court without negotiating with the opposition.

“This would create an even more accelerated process of total control of the government,” said Celia Medrano, a Salvadoran human rights advocate. Analysts fear Bukele could press for a new constitution that would abolish restrictions on consecutive presidential terms.

The president’s party was also expected to make strong gains in the vote for local officials in 262 municipalities.

Bukele, 39, rode an anti-corruption wave sweeping the region to a landslide victory in 2019, becoming Latin America’s youngest president. He developed warm ties with the Trump administration, which prioritized choking off immigration from Central America. Bukele became close to President Donald Trump’s ambassador, Ron Johnson, posting pictures of the men and their wives on a boating trip a year ago.

The Biden administration has laid out a starkly different Central America policy, focused on fighting corruption, strengthening democracy and encouraging economic growth to stymie migration. In a striking sign of the new era, Bukele was unable to secure meetings with Biden’s top Latin America officials during a recent trip to Washington.

“He is seen with great alarm by the new team,” said one U.S. diplomat familiar with Central America. “At the same time, there is a very clear understanding of his political power at this moment in El Salvador.” The diplomat, who spoke on the condition of anonymity to speak candidly, noted that Bukele “emerged from a rejection of the political class,” a trend in elections throughout the region.

Bukele is the first Salvadoran president chosen from outside the two parties — the right-wing ARENA and left-wing FMLN — that have dominated politics since the end of the 12-year civil war in 1992.

Corruption scandals, coupled with resentment about the lack of economic and security improvements, led in recent years to widespread voter frustration. Bukele presented a fresh image, appearing in leather jackets and firing off sharp tweets about his accomplishments. He won office by promising to root out political corruption and rid the country of warring gangs.

Supporters credit him with reducing a staggeringly high homicide rate, responding aggressively to the coronavirus pandemic and denouncing the corruption of past governments.

“Bukele has brought to light everything [corrupt], and that’s why they don’t want him,” said Henry, a 47-year-old street vendor in San Salvador, who spoke on the condition that his last name not be used to comment freely. “They criticize him for doing things right.”

Bukele’s party is based more on his image and performance than on a traditional political ideology.

“People aren’t voting for parties, they’re voting for Nayib Bukele,” said Manuel Escalante, a lawyer with the Institute of Human Rights at the University of Central America.

But human rights groups have warned about his authoritarian tendencies. Bukele has labeled critics traitors and attacked independent media. He has ignored rulings by the five-member Constitutional Court against his strict coronavirus quarantines, saying his measures were aimed at saving lives. “Five people won’t decide the deaths of hundreds of thousands of Salvadorans,” Bukele declared on Twitter.

When legislators didn’t approve a loan in February last year to finance his security plan, Bukele marched with soldiers into the Legislative Assembly chamber, stirring traumatic memories of past dictatorships.

“For me it’s clearly a return, not to the war, but to the period before the war when the military dominated our country,” Zamora said.

In the lead-up to the elections, Bukele intensified his criticism of political opponents and journalists. Amid rising political tensions, gunmen killed two FMLN members at a campaign event in January, a shocking act of political violence. Bukele accused the FMLN of staging the attack to garner sympathy before elections but has produced no evidence. Three suspects have been arrested, including one who works as a security guard for the Health Ministry. Authorities say the motive is unclear.

Bukele has rejected criticism of his governing style. If he were a dictator, he argues, he already would have taken control of the government.

The Biden administration is still assembling its foreign policy team, but the U.S. change in policy toward Central America is clear. Biden has canceled “safe third country” agreements promoted by Trump that would have sent asylum seekers from the U.S. border to El Salvador, Guatemala and Honduras.

“There isn’t any question the Trump administration had a very transactional approach to El Salvador, and the Northern Triangle as a whole,” said Geoff Thale, president of the Washington Office on Latin America, a human rights group.

Bukele has a strong popular mandate and “we have to respect that,” Thale said. “It doesn’t mean we don’t have interests. It doesn’t mean we can’t make decisions about where U.S. assistance is directed and goes, and under what conditions.”

Sheridan reported from Washington.