Valentin Varennikov, who has died aged 85, was the epitome of a generation of diehards who refused to accept the changes to the Soviet Union introduced by Mikhail Gorbachev. A veteran of the second world war, he rose through the cold war military hierarchy to become first deputy chief of the Soviet general staff and then served as the Defence Ministry's envoy in Afghanistan.

He came to international prominence as one of the 12 conspirators behind the state committee on the state of national emergency, which instigated the August 1991 putsch against Gorbachev. In later years, he was a member of the Duma and remained a hawkish defender of Soviet achievements.

Varennikov, who was born in Krasnodar, southern Russia, owed his career to the structures of Stalin's Soviet Union. He said that from the age of five he had dreamed of a military career and, in 1941, as Adolf Hitler prepared Barbarossa - his invasion of the Soviet Union - Varennikov entered officer cadet school. Graduating in 1942, he was sent straight to the front, fighting first in the defence of Stalingrad then, as Soviet forces pushed the German invaders back westwards, on the Ukrainian and Belorussian fronts. He was wounded three times.

As a member of Marshal Zhukov's forces he took part in the battle of Berlin and the capture of the Reichstag, a role that earned him the privilege of carrying seized Nazi banners and throwing them at the foot of Lenin's tomb in Red Square as part of Moscow's triumphant victory celebrations in 1945.

Varennikov spent the next five years in East Germany before returning to the Soviet Union. In 1954, the year after the death of Stalin, Varennikov graduated from Moscow's elite Frunze military academy. His subsequent career saw him involved in some of the most significant theatres of the cold war, overseeing operations and military training of Soviet allies in Angola, Syria and Ethiopia as Moscow and Washington sought to expand their spheres of influence in the developing world.

In 1978 he was made a general and a year later joined the Soviet Army's general staff. The pinnacle of Varennikov's career was during the disastrous invasion of Afghanistan in December 1979. Orchestrated during the final years of the rule of Leonid Brezhnev, by the time of his death in 1982, the Soviet campaign was already bogged down in guerrilla fighting and military commanders were discovering that their strategy was hampered by political demands, difficult terrain and problems of effective deployment of air power.

In 1984, Varennikov was appointed commander of Soviet forces in the country and, within a year, following Gorbachev's appointment as Communist party general secretary in 1985, Moscow's policy had turned decisively towards one of military disengagement from Afghanistan. Speaking in 2001 as American forces entered the country in the aftermath of 9/11, he cautioned against a military campaign and warned that Washington would suffer a similar fate to Moscow.

Varennikov was seconded to take charge of soldiers involved in the clean-up and evacuation of Chernobyl following the 1986 nuclear accident and then returned to head operations in Afghanistan where he remained until the withdrawal was completed in 1989. His role in Afghanistan earned Varennikov the title Hero of the Soviet Union and promotion to deputy defence minister. But by then the country to which he had devoted his life was heading towards disintegration as the Warsaw pact broke up and demands for autonomy from the Soviet Union's constituent republics grew ever more vociferous.

As opposition to Gorbachev grew among Kremlin hardliners, Varennikov knew which side he was on. He offered support to the coup plotters who, in August 1991, placed Gorbachev under house arrest in his Black Sea holiday home and declared a state of emergency in Moscow. The coup lasted three days with Boris Yeltsin rallying the country to the defence of its president. The ringleaders, among them Varennikov, were soon arrested, charged with treason and even briefly imprisoned.

By 1994, as the economic troubles of Yeltsin's Russia mounted, the events that had led to the collapse of the Soviet Union were no longer in the forefront of public or political attention and the 12 were offered an amnesty by a sympathetic Duma. All, with the exception of Varennikov, accepted the offer.

Determined to have his day in court, and, as he saw it, hold Gorbachev and Yeltsin to account, he went on trial. The opening days of the trial saw nationalist and communist supporters cheer on Varennikov, who saw himself as a martyr to the Soviet cause. "I have no regrets about what I did, but I have a bitter feeling that we failed to save the country," he said in his defence.

Interest in the trial soon waned and Varennikov's rhetoric fell on empty seats. The Russian supreme court ruled that Gorbachev could not be summoned as a witness and Varennikov was acquitted. The court accepted that he had acted out of a sense of patriotic duty.

The trial, however, did act as a political springboard for Varennikov, who was elected to the Russian parliament in 1995 as part of the Rodina (Homeland) nationalist block before returning to his spiritual home in the Communist party. As a deputy, he spoke out to defend the Soviet past, his hero Stalin (who last year he unsuccessfully championed in a Russian TV poll to decide the country's greatest historical figure) and, as president of the committee on veterans' affairs, spoke up for what he saw as the mistreatment of disenfranchised former Soviet military families living in newly independent states.

Varennikov's hawkish defence of the glories of the Soviet era found a more sympathetic ear during Vladimir Putin's presidency, which sought to restore a sense of pride in Russia's past. The now elderly, but still active Varennikov was received frequently by Putin and given the largely ceremonial title of defence ministry inspector general. He appeared at military and ceremonial occasions, even travelling to Afghanistan last year and making his final appearance at a second world war remembrance ceremony in the autumn.

Interviewed by national and foreign academics and press, Varennikov, his five-row-deep military honours on his breast, remained a hawk until the end. Interviewed on the occasion of Ronald Reagan's death, he blamed America for the destruction of the Soviet Union, but said Reagan was only instrumental in the collapse of communism "because he was leader when it happened".

For him the second world war remained the Soviet Union's finest hour and demonstrated the virtues of the country and its leadership. It was a sentiment that many of Varennikov's generation believed with the same passion.

Varennikov's death in Moscow's elite military Burdenko hospital was met by warm tributes in Russian military circles and among veterans groups. He was, President Dmitry Medvedev said "a true patriot" and a "distinguished commander".

Varennikov's wife and one son predeceased him. He is survived by his son Vladimir, a general lieutenant.

• Valentin Ivanovitch Varennikov, soldier and politician, born 15 December 1923; died 6 May 2009