A senior Haitian police official was shopping at his local supermarket on a recent weekday when someone caught his eye: the country’s most wanted man.

The official, Ernst Dorfeuille, recognized Joseph Félix Badio, a former military officer who had focused on drug and corruption cases at the interior and justice ministries, immediately because he had once worked with him.

Now Mr. Badio was a fugitive, the target of a warrant seeking to question him about the key role the police say he played in an infamous crime: the assassination of Haiti’s president, Jovenel Moïse, in July 2021.

Mr. Dorfeuille summoned help, and within minutes, four police officers armed with assault rifles arrived and detained Mr. Badio as he was about to drive away from the supermarket outside Haiti’s capital.

Mr. Dorfeuille confirmed to The Times details about Mr. Badio’s capture that have appeared in Haiti’s news media, but declined a more extensive interview.

How Mr. Badio, who has been accused by some of the men implicated in the assassination plot of giving the order to kill Mr. Moïse, was able to evade the Haitian authorities for more than two years remains unclear.

When he was detained, Mr. Badio was driving a vehicle registered to an employee of the Justice Ministry, according to the police.

His arrest prompted reactions of gleeful astonishment among many Haitians who have grown cynical in a country where corruption and impunity are often the norm.

Pierre Espérance, the executive director of a leading Haitian human rights organization, said the seemingly chance arrest of Mr. Badio raised questions of how aggressively he was being sought.

“He was untouchable, because he knew too much,” Mr. Espérance said.

Mr. Moïse was gunned down in his bedroom in the early hours of July 7, 2021, after the police say his official residence was attacked by a team of 20 Colombian former soldiers hired by a Miami-area security firm.

Two parallel investigations into the assassination are ongoing in Haiti and South Florida. Dozens of people are imprisoned in Haiti, but so far none have been charged.

In Miami, 11 people were indicted in February in federal court for their roles in the conspiracy. Three have pleaded guilty, including one of the Colombians, Germán Rivera, who received a life sentence last month. All three were charged with conspiracy to kidnap and kill a person outside the United States.

Mr. Badio, who has been described in a detailed Haitian police report as the plot’s “orchestra leader,” has not been charged in the assassination. In Haiti, official charges tend to come much later in the legal process.

The Haitian police said Mr. Badio rented two vehicles that transported the president’s killers, as well as a house on the same street as Mr. Moïse’s residence to conduct surveillance.

After his arrest, Mr. Badio appeared briefly before a judge and was then transferred to Haiti’s main prison. Jonas Mezilus, a lawyer representing Mr. Badio, said that because his client had not been formally charged, he did not know how he would plead.

A year ago, Mr. Badio issued an audio statement to a Haitian news media outlet proclaiming his innocence, saying he was being made a “scapegoat” for Mr. Moïse’s assassination and was willing to speak to the authorities, including the F.B.I.

“I’m available today,” he said. “I’m a slave to the law.”

U.S. court documents filed as part of the indictment in South Florida refer to an unnamed “co-conspirator” who conveyed the order to kill the president.

Some lawyers representing defendants charged in South Florida believe that Mr. Badio is the co-conspirator and that he could ultimately also face legal charges in the United States. A Department of Justice spokeswoman declined to comment about Mr. Badio’s status.

Given that Mr. Badio has never been questioned in Mr. Moïse’s killing, legal experts say he could provide vital answers to a case that remains shrouded in mystery.

U.S. prosecutors argue that the owners of the Miami-area security firm, Counter Terrorist Unit, planned and financed the assassination, seeking to profit from lucrative contracts under a new government. But they have left open the questions of whether there were other masterminds in Haiti and what role they may have played in the plot.

Haiti’s prime minister, Ariel Henry, has praised Mr. Badio’s arrest. “This is a major step forward in the investigation,” he said in a statement.

But Mr. Henry himself has been linked to the assassination by Haitian authorities who say phone records show that Mr. Badio called Mr. Henry several times in the days before and in the hours after Mr. Moïse’s killing.

Last year when a judge in the case requested that Mr. Henry answer questions about his relationship with Mr. Badio, he was fired by the justice minister and fled the country. At the time, the judge wrote that there were “enough compromising elements” to prosecute Mr. Henry.

Mr. Henry has denied any involvement. In response to questions for this article, his spokesman said that Mr. Henry had many phone calls the day of Mr. Moïse’s killing, “but none with Mr. Badio.’’

Mr. Badio is a former Haitian Army officer who worked in strategic communications before entering the civil service. The Times contacted a dozen former and current officials who worked with him, but none would speak on the record.

His father emigrated to New York in the early 1960s, according to a person who worked with Mr. Badio in the Haitian government and asked to remain anonymous because he feared for his safety speaking about Mr. Badio publicly.

The younger Mr. Badio lived briefly in New York and attended Medgar Evers College, part of the City University of New York system, according to his Facebook page. The college confirmed that someone named Joseph Félix Badio studied there from 1992 to 1993, though there was no record that he graduated.

He later bought a four-bedroom house in a residential neighborhood in Rockland County, just north of New York City, where his wife and two children still live, according to property and phone records. A Times reporter visited the house, but no one answered the door.

The person who worked with him said Mr. Badio was fascinated with guns and all things related to security and intelligence. He also seemed resentful toward those in power who failed to recognize his talents sufficiently, according to several people who had worked with him and had followed his career.

“Badio was extremely well connected across not just the political spectrum, but in security, at a pretty high level,” said Jake Johnston, a Haiti expert at the Center for Economic and Policy Research in Washington, who has researched Mr. Badio’s record.

Referring to Mr. Badio’s superiors in Haiti’s government, Mr. Johnston said: “He was somebody also that these people relied upon to handle things. He had a reputation as somebody who was always around to get things done.”

Mr. Espérance, the director of the human rights group, said he met with Mr. Badio once a decade ago. He recalled that Mr. Badio “talked about his relationship with U.S. agencies, the F.B.I. and the Drug Enforcement Administration, but you never knew if it was fake or not.”

A State Department spokeswoman confirmed that Mr. Badio had attended an anti-gang conference in the United States in 2009.

Two months before Mr. Moïse’s assassination, Mr. Badio was fired from an anti-corruption unit in the Justice Ministry for accepting $30,000 from a man in jail accused in the murder of a well-known local radio station owner, according to a letter from Mr. Badio’s boss at the ministry, as well as a ministry news release.

The transcripts, which point to Mr. Badio’s involvement in the plot, are part of the prosecution’s evidence in the South Florida case and were reviewed by The Times.

In his audio message to the Haitian news outlet, Mr. Badio denounced unnamed members of Haiti’s government who he claimed had also been involved in the assassination plot.

“If you think you’re going to get away with it, by executing me,” he said, “well, you’re knocking on the wrong door.”

Camille Baker contributed reporting from Rockland County, N.Y., and Harold Isaac from Port-au-Prince, Haiti.