KRAMATORSK, July 7 (Reuters) - Former Russian President Dmitry Medvedev said attempts by the West to punish a nuclear power such as Russia for the war in Ukraine risked endangering humanity, as the near five-month conflict leaves cities in ruins and thousands homeless.

Russia's Feb. 24 invasion of Ukraine has triggered the most serious crisis in relations between Russia and the West since the 1962 Cuban Missile Crisis, when many people feared the world was on the brink of nuclear war.

U.S. President Joe Biden says Russian President Vladimir Putin is a war criminal and has led the West in arming Ukraine and imposing crippling sanctions on Russia.

"The idea of punishing a country that has one of the largest nuclear potentials is absurd. And potentially poses a threat to the existence of humanity," Medvedev, now deputy chairman of the Russian Security Council, said on Telegram on Wednesday.

Russia and the United States control about 90% of the world's nuclear warheads, with around 4,000 warheads each in their military stockpiles, according to the Federation of American Scientists.

Medvedev cast the United States as an empire which had spilled blood across the world, citing the killing of Native Americans, U.S. nuclear attacks on Japan and a host of wars ranging from Vietnam to Afghanistan.

Attempts to use courts or tribunals to investigate Russia's actions in Ukraine would, Medvedev said, be futile and risk global devastation. Ukraine and its Western allies say Russian forces have engaged in war crimes.

Putin launched his invasion, calling it a "special military operation", to demilitarise Ukraine, root out what he said were dangerous nationalists and protect Russian speakers in that country.

Ukraine and its allies say Russia launched an imperial-style land grab, sparking the biggest conflict in Europe since World War Two.

After failing to seize the capital Kyiv early, Russia is now waging a war of attrition for Ukraine's Donbas region, parts of which are controlled by Russian separatist proxies.

On Sunday, Putin claimed his biggest victory when Ukrainian forces withdrew from Luhansk province. Russian forces then launched an offensive to take neighbouring Donetsk province. Donetsk and Luhansk comprise the Donbas.

Russia says it wants to wrest control of the eastern and heavily industrial region on behalf of Moscow-backed separatists in two self-proclaimed people’s republics.