The 12 shots fired on Wednesday evening, killing an Ecuadorean presidential candidate as he exited a campaign event, marked a dramatic turning point for a nation that a few years ago seemed an island of security in a violent region.

A video of the moments just before the killing of the candidate, Fernando Villavicencio, began circulating online even before his death had been confirmed. And for many Ecuadoreans, those shots echoed with a bleak message: Their nation was forever changed.

“I feel that it represents a total loss of control for the government,” said Ingrid Ríos, a political scientist in the city of Guayaquil, “and for the citizens, as well.”

Ecuador, a country of 18 million on South America’s western coast, has survived authoritarian governments, financial crises, mass protests and at least one presidential kidnapping. It has never, however, been shaken by the kind of drug-related warfare that has plagued neighboring Colombia, unleashing violence that has killed thousands, corroded democracy and turned citizens against one another.

Hours after the candidate’s killing, President Guillermo Lasso declared a state of emergency, suspending some civil liberties, he said, to help him deal with growing crime.

And on Thursday afternoon, Ecuador’s interior minister, Juan Zapata, said that six suspects arrested in connection with Mr. Villavicencio’s killing were all Colombian, adding a new dimension to a story line that already seemed to be imported from another place.

In the past five years, the narco-trafficking industry has gained extraordinary power in Ecuador, as foreign drug mafias have joined forces with local prison and street gangs. In just a few years, they have transformed entire swaths of the country, extorting businesses, recruiting young people, infiltrating the government and killing those who investigate them.

The similarities to the problems that plagued Colombia in the 1980s and ’90s, as narco-trafficking groups assumed control of broad parts of the country and infiltrated the government, have become almost impossible for Ecuadoreans to ignore.

On Thursday, some began to compare Mr. Villavicencio’s killing to that of Luis Carlos Galán, a Colombian presidential candidate gunned down on the campaign trail in 1989. Like Mr. Villavicencio, Mr. Galán was a harsh critic of the illegal drug industry.

Mr. Galán’s death still reverberates in Colombia as a symbol of the dangers of speaking out against criminal power and of the inability of the state to protect its citizens.

More broadly, Colombia is still grappling with the effects of the drug-trafficking industry, which continues to hold sway over the electoral process and is responsible for the deaths and displacement of thousands of people each year.

On Thursday, mourners gathered outside a morgue in the Ecuadorean capital, Quito, where Mr. Villavicencio’s body was being held. The air filled with desperate cries. Irina Tejada, 48, a teacher, wept as she spoke.

“They’ve stolen our hero,” she said. Then, addressing corrupt politicians, she went on: “Why don’t they side with our people, not with those criminal narcos? The pain and outrage!”

Soon, the silver hearse carrying Mr. Villavicencio’s body left the morgue, and the crowd began to clap, at first mournfully, then with a rapid anger.

People screamed at the police escort surrounding the body.

“Now you protect him, when it is too late!” a woman shouted.

Mr. Villavicencio, who had worked as a journalist, activist and legislator, was polling near the middle of a group of eight candidates in a presidential election set for Aug. 20. He was among the most outspoken about the link between organized crime and government officials.

On Wednesday evening, he arrived at a school in Quito, the capital, where he stood on a stage in front of a packed crowd and spoke out “against the mafias that have subjugated this homeland.” Then, as he exited the school under an enormous banner that bore his face and the words “presidente,” the shots were fired.

Mr. Lasso, the president, immediately blamed the death on “organized crime.” The national prosecutor’s office quickly said that one suspect had been killed and six others arrested.

The following day, Mr. Lasso said he had requested the help of the F.B.I., which agreed to assist in investigating the case.

Just after Mr. Villavicencio’s death, Carlos Figueroa, a member of his campaign who had witnessed the shooting, spoke to The Times, his voice wobbly.

“The mafias are too powerful,” he said. “They have taken over our country; they have taken over the economic system, the police, the judicial system.”

“We are desperate,” he continued. “We don’t know our country’s future, in which hands, or by whom, it will be taken over.”

Mr. Villavicencio, 59, gained prominence as an opponent of correísmo, the leftist movement of former President Rafael Correa, who served from 2007 to 2017 and still holds political power in Ecuador.

In the days before the assassination, Mr. Villavicencio had appeared on television, saying that he had received three specific threats from members of a criminal group called Los Choneros.

In an initial threat, he said, representatives of a Choneros leader named Fito visited a member of Mr. Villavicencio’s team “to tell them that if I keep mentioning Fito’s name, mentioning the Choneros, they’re going to break me. That’s how it was. And my decision was to continue with the electoral campaign.”

Mr. Villavicencio’s killing casts a pall on an already-contentious presidential election, which will go on as planned. A candidate who has Mr. Correa’s backing, Luisa González, is leading in the polls.

Yet, because Mr. Villavicencio was such a harsh critic of Mr. Correa, some Ecuadoreans have begun to blame correísta candidates for Mr. Villavicencio’s death. There is no evidence of their involvement.

“Not a single vote for correísmo,” one woman chanted outside the morgue.

Other voters said they were turning toward Jan Topic, a candidate and former soldier in the French Foreign Legion whose focus has been taking a hard line on security, and who has been mirroring the promises of El Salvador’s president, Nayib Bukele. Mr. Bukele’s hard line on gangs, including mass imprisonments, has helped drive down violence, but he has also been accused of violating civil liberties.

Germán Martínez, a coroner who happened to be at the morgue where Mr. Villavicencio’s body lay on Thursday, said that after the killing, he had decided to switch his vote to Mr. Topic.

“Where are we, as Ecuadoreans?” he asked. “We can’t remain with our heads low. We need to fight criminals. We need a strong hand.”

Genevieve Glatsky contributed reporting from Bogotá, Colombia.