The former rebel and longtime senator’s victory sets the third largest nation in Latin America on a sharply new path.BOGOTÁ, Colombia — For the first time, Colombia will have a leftist president.Gustavo Petro, a former rebel and a longtime legislator, won Colombia’s presidential election on Sunday, galvanizing voters frustrated by decades of poverty and inequality under conservative leaders, with promises to expand social programs, tax the wealthy and move away from an economy he has called overly reliant on fossil fuels.His victory sets the third largest nation in Latin America on a sharply uncertain path, just as it faces rising poverty and violence that have sent record numbers of Colombians to the United States border; high levels of deforestation in the Colombian Amazon, a key buffer against climate change; and a growing distrust of key democratic institutions, which has become a trend in the region.Mr. Petro, 62, received more than 50 percent of the vote, with more than 99 percent counted Sunday evening. His opponent, Rodolfo Hernández, a construction magnate who had energized the country with a scorched-earth anti-corruption platform, won just over 47 percent.Shortly after the vote, Mr. Hernández conceded to Mr. Petro.“Colombians, today the majority of citizens have chosen the other candidate,” he said. “As I said during the campaign, I accept the results of this election.”Mr. Petro took the stage Sunday night flanked by his vice-presidential pick, Francia Márquez, and three of his children. The packed stadium went wild, with people standing on chairs and holding phones aloft.“This story that we are writing today is a new story for Colombia, for Latin America, for the world,” he said. “We are not going to betray this electorate.”He pledged to govern with what he has called “the politics of love,” based on hope, dialogue and understanding.Just over 58 percent of Colombia’s 39 million voters turned out to cast a ballot, according to official figures.The victory means that Ms. Márquez, an environmental activist who rose from poverty to become a prominent advocate for social justice, will become the country’s first Black vice president.Francia Márquez, at a campaign event last month in Yumbo, Colombia.Federico Rios for The New York TimesMr. Petro and Ms. Márquez’s victory reflects an anti-establishment fervor that has spread across Latin America, exacerbated by the pandemic and other longstanding issues, including a lack of opportunity.“The entire country is begging for change,” said Fernando Posada, a Colombian political scientist, “and that is absolutely clear.”In April, Costa Ricans elected to the presidency Rodrigo Chaves, a former World Bank official and political outsider, who took advantage of widespread discontent with the incumbent party. Last year, Chile, Peru and Honduras voted for leftist leaders running against candidates on the right, extending a significant, multiyear shift across Latin America.As a candidate, Mr. Petro had energized a generation that is the most educated in Colombian history, but is also dealing with 10 percent annual inflation, a 20 percent youth unemployment rate and a 40 percent poverty rate. His rallies were often full of young people, many of whom said they feel betrayed by decades of leaders who had made grand promises, but delivered little.“We’re not satisfied with the mediocrity of past generations,” said Larry Rico, 23, a Petro voter at a polling station in Ciudad Bolívar, a poor neighborhood in Bogotá, the capital.Mr. Petro’s win is all the more significant because of the country’s history. For decades, the government fought a brutal leftist insurgency known as the Revolutionary Armed Forces of Colombia, or FARC, with the stigma from the conflict making it difficult for a legitimate left to flourish.But the FARC signed a peace deal with the government in 2016, laying down their arms and opening space for a broader political discourse.Mr. Petro had been part of a different rebel group, called the M-19, which demobilized in 1990, and became a political party that helped rewrite the country’s constitution. Eventually, Mr. Petro became a forceful leader in the country’s opposition, known for denouncing human rights abuses and corruption.Voters cast their ballots in Colombia’s presidential election, in Bucaramanga, on Sunday.Nathalia Angarita for The New York TimesOn Sunday, in a wealthy part of Bogotá, Francisco Ortiz, 67, a television director, said he had also voted for Mr. Petro.“It’s been a long time since we had an opportunity like this for change,” he said. “If things will get better, I don’t know. But if we stick with the same, we already know what we’re going to get.”The win could also test the United States’ relationship with its strongest ally in Latin America. Traditionally, Colombia has formed the cornerstone of Washington’s policy in the region.But Mr. Petro has criticized what he calls the United States’ failed approach to the drug war, saying it has focused too much on eradication of the coca crop, the base product in cocaine, and not enough on rural development and other measures.Mr. Petro has said he embraces some form of drug legalization, that he will renegotiate an existing trade deal with the United States to better benefit Colombians and that he will restore relations with the authoritarian government of president Nicolás Maduro of Venezuela, all of which could create conflict with the United States.About two million Venezuelan migrants have fled to Colombia in recent years amid an economic, political and humanitarian crisis.Colombian soldiers in a coca growing area near the border with Venezuela. The United States has spent billions of dollars in Colombia in the past two decades to help its governments halt the production and export of cocaine, to little effect.Federico Rios for The New York TimesMr. Petro, in an interview earlier this year, said he believed he could work well with the government of President Biden, adding that his relationship with the United States would focus on working together to tackle climate change, specifically halting the rapid erosion of the Amazon.“There is a point of dialogue there,” he said. “Because saving the Amazon rainforest involves some instruments, some programs, that do not exist today, at least not with respect to the United States. It is, in my opinion, the priority.”Both Mr. Petro and Mr. Hernández had beaten Federico Gutiérrez, a former big city mayor backed by the conservative elite, in a first round of voting on May 29, sending them to a runoff.Both men had billed themselves as anti-establishment candidates, saying they were running against a political class that had controlled the country for generations.Among the factors that most distinguished them was how they viewed the root of the country’s problems.Mr. Petro believes the economic system is broken, overly reliant on oil export and a flourishing and illegal cocaine business that he said has made the rich richer and poor poorer. He is calling for a halt to all new oil exploration, and a shift to developing other industries.He has also said he will introduce guaranteed work with a basic income, move the country to a publicly controlled health system and increase access to higher education, in part by raising taxes on the rich.“What we have today is the result of what I call ‘the depletion of the model,’” Mr. Petro said in the interview earlier this year, referring to the current economic system. “The end result is a brutal poverty.”His ambitious economic plan has, however, raised concerns. One former finance minister called his energy plan “economic suicide.”Mr. Hernández did not want to overhaul the economic framework, but said it was inefficient because it is riddled with corruption and frivolous spending. He had called for combining ministries, eliminating some embassies and firing inefficient government employees, while using savings to help the poor.Mr. Hernández during a campaign event this month in Barranquilla, Colombia.Federico Rios for The New York TimesOne Hernández supporter, Nilia Mesa de Reyes, 70, a retired ethics professor who voted in an affluent section of Bogotá, said that Mr. Petro’s leftist policies, and his past with the M-19, terrified her. “We’re thinking about leaving the country,” she said.Mr. Petro’s critics, including former allies, have accused him of arrogance that leads him to ignore advisers and struggle to build consensus. When he takes office in August, he will face a deeply polarized society where polls show growing distrust in almost all major institutions.He has vowed to serve as the president of all Colombians, not just those who voted for him.On Sunday, at a high school-turned-polling station in Bogotá, Ingrid Forrero, 31, said she saw a generational divide in her community, with young people supporting Mr. Petro and older generations in favor of Mr. Hernández.Her own family calls her the “little rebel” because of her support for Mr. Petro, whom she said she favors because of his policies on education and income inequality.“The youth is more inclined toward revolution,” she said, “toward the left, toward a change.”Megan Janetsky contributed reporting from Bucaramanga, Colombia, and Sofía Villamil and Genevieve Glatsky contributed reporting from Bogotá. More