The Russians, who were tried in absentia and are believed to be in Russia, “knowingly tried to terrorize Montenegrins, attack others, threaten and hurt basic constitutional and social structures,” the judge, Susana Mugosa, said on Thursday in court in Podgorica, the capital.

Judge Mugosa sentenced the two, who were referred to throughout the trial by the pseudonyms on their fake passports, Eduard V. Shirokov and Vladimir N. Popov, to 15 and 12 years in prison. It is unlikely they will serve the terms.

Two Montenegrin politicians accused of coordinating with them to disrupt a parliamentary election in October 2016, Andrija Mandic and Milan Knezevic, were each sentenced to five years in prison. The other sentences ranged from parole to eight years in prison.

The 2016 parliamentary vote in Montenegro, formerly a part of Yugoslavia, was viewed as a referendum on membership in NATO, which had been agreed to but had not yet taken effect. On the eve of the vote, more than 20 Serbian nationalists and others were arrested, and eventually 14 people were accused of plotting to disrupt the election and install an anti-NATO government.

Instead, the governing Democratic Party of Socialists fared well enough to remain in power, and the country joined the alliance in 2017.

Image

Opposition leaders from Montenegro’s Democratic Front, Andrija Mandic, left, and Milan Knezevic, were accused of coordinating with others to disrupt a parliamentary election and were each sentenced to five years in prison.CreditSavo Prelevic/Agence France-Presse — Getty Images

Often at the heart of those allegations is the ruthless and effective agency formerly called the G.R.U., and now known as the G.U., or Main Directorate. For years it was a black box to foreign governments, but its activities have spilled into the open in recent years with a flurry of operations in the West.

Evidence introduced at the trial showed that the two Russian defendants used crude but effective spycraft, asking one recruit to save a secret number on his cellphone as “taxi for the hotel” and to arrange a clandestine meeting with “an invitation to grab a beer.”

The case roiled politics in Montenegro, which has a population of about 600,000 people. The government called it evidence of a threat to democracy, with critics and defense lawyers saying it was an effort by the president, Milo Djukanovic, to attack domestic political opponents.

People who disputed the Kremlin connection said the evidence showed such bungling that it could not have been a true Russian espionage plot. Money for the coup plot, for example, was wired by Western Union using the headquarters of the G.R.U. in Moscow as the sender’s address.

“If Russia wanted to organize a coup here, they could do it in 20 minutes,” Mr. Knezevic, one of the defendants and head of an opposition party, said in an interview last fall. “Nobody believes in this coup besides the special prosecutor.”

But reckless operations easily unraveled by Western intelligence agencies have been a hallmark of recent G.R.U. activities, and in Montenegro the apparent incompetence of the Russians and those interacting with them did not convince the judge of innocence.

Awakened to the range and recklessness of the G.R.U.’s activities, Western governments are retaliating. In 2018, more than 150 Russian diplomats were expelled from different countries as punishment for the nerve agent attack in Salisbury, England, on a former G.R.U. officer, Sergei V. Skripal. In October, officials in the Netherlands, Britain and the United States accused the agency of a string of cyberattacks against Western institutions.

After prosecutors indicted the two Russians in 2017, they released images of their passports, which showed that the photograph of the supposed Mr. Shirokov matched that of a former Russian military attaché to Poland, Eduard Shishmakov, whom the Poles had expelled for spying.

Suspicions of Russian intelligence ties grew last year, after two Russian men, whom the British government called G.R.U. agents, were accused in the nerve agent attack on Mr. Skripal. He and three other people who were exposed to the agent survived, but one woman died.

The two Russians accused in the Skripal case had nine-digit passport numbers that were just three apart, and the “Shirokov” passport in the Montenegro case was separated from one of them by just 26. Bellingcat, a group analyzing open-source information about intelligence activities, pointed to the similar numbers as evidence that they had been obtained by the Russian spy agency.

Mr. Shishmakov plotted the coup with a Serbian nationalist, Sasa Sindjelic, and members of the Democratic Front, an alliance of right-wing parties, prosecutors said. Mr. Sindjelic became a witness for prosecutors and was not charged. After the trial, he recanted his testimony.

The plan was to claim electoral fraud on the day of the voting and seize the Parliament building, Mr. Sindjelic testified. He described precautions like storing a sensitive phone number under a bland listing and using code for meetings, and he said the Russians had given him encrypted telephones and the equivalent of about $200,000 to plan the coup.

“I was giving away money like Santa Claus,” Mr. Sindjelic testified at the trial. He said he had even considered keeping receipts for all the money he was disbursing.

“I asked if people needed to sign a piece of paper confirming they took the money,” Mr. Sindjelic testified.

In this instance, at least, caution prevailed. He said the Russians told him not to.

A version of this article appears in print on , on Page A9 of the New York edition with the headline: 2 Russians, Believed to Be Agents, Are Among 14 Convicted in Montenegro Coup Plot. Order Reprints | Today’s Paper | Subscribe