A court in Montenegro has sentenced alleged Russian military intelligence agents, opposition politicians and a number of associates to jail terms over an alleged 2016 attempt to organise a coup in the country and prevent it from joining Nato.

The chief judge, Suzana Mugoša, said Eduard Shishmakov and Vladimir Popov, alleged GRU agents, were guilty of attempted terrorism and creating a criminal organisation, and handed them sentences of 15 and 12 years respectively. The pair were tried in absentia. Two politicians, Andrija Mandić and Milan Knežević, were each sentenced to five years in jail.

If the prosecutors’ account of events at the trial is correct, the coup attempt would represent one of the most audacious Russian foreign policy gambits in recent times. The verdict said the group intended to take over parliament on election day in October 2016, assassinate the then prime minister, Milo Đukanović, and install a pro-Kremlin leadership.

Montenegro authorities claim the plot was thwarted on the basis of tipoffs from western spy agencies, and the suspects rounded up before the plan could be put into action. Dmitry Peskov, the spokesman for the Russian president, Vladimir Putin, has previously dismissed allegations of Russian involvement as “absurd”, claiming Russia does not meddle in the internal affairs of other countries.

The verdict handed down on Thursday said the Russian pair coordinated the attempted coup from Serbia and were allowed to leave the country by Serbian authorities. Diplomatic sources told the Guardian at the time that the Russians were allowed to leave the country on the plane of Nikolai Patrushev, the head of Russia’s security council.

A source close to the Belgrade government told the Guardian at the time that Patrushev, a former head of Russia’s FSB domestic security service, apologised for what he called a rogue operation that was conducted without the Kremlin’s sanction. A Russian security council official responded to the Guardian report by saying Patrushev “didn’t apologise to anyone, because there is nothing to apologise for”.

The investigation website Bellingcat has identified the two Russians sentenced on Thursday as probable GRU agents operating under pseudonyms.

The judge said the aim of the coup was “to change the electoral will” of the people and “prevent Montenegro from joining Nato”. She said she believed the two politicians had travelled to Moscow to take instructions from GRU operatives.

The GRU has been accused of a number of audacious operations in recent years, including the 2018 attack on Sergei Skripal and his daughter Yulia in Salisbury using the nerve agent novichok, and hacking the 2016 US presidential campaign.

The details of the Montenegro plot remain murky, and sceptics have pointed to a number of oddities about the way the coup suspects were rounded up, discrepancies in the prosecution testimony and key witnesses recanting their testimony.

A source in Serbia told the Guardian recently that the coup plot story was “all true, but it was terribly organised”. Others have speculated that there may have been a genuine plot to cause disruption on election day, but that Montenegrin authorities exaggerated the details.

Mandić and Knežević have dismissed the court case as politically motivated and an attempt to remove them from public life. The two men, both ethnic Serbs, are strong opponents of Đukanović and of Montenegro’s Nato membership. The country joined the alliance in 2017, despite an almost 50/50 split inside Montenegro between supporters and opponents of the move.

Đukanović, who supported Nato accession, has been the most powerful man in Montenegro since 1991. His critics say western partners turn a blind eye to corruption and rule of law issues due to his pro-western stance.