Russia has agreed to cancel $4.5bn (£2.3bn) of Libyan debt in exchange for major contracts for Russian firms. The announcement came during a visit to Tripoli on Thursday by the Russian President, Vladimir Putin.

The two countries signed deals on energy co-operation, military assistance and construction of a 500km (310-mile) railway line in Libya. Libya was a big importer of Soviet weaponry during the Cold War, when it accumulated large debts.

Russia's state gas monopoly Gazprom plans large-scale exploration and production projects with Libya's national energy company. They will include liquefied natural gas installations and gas-fired electricity plants in Libya.

Russia will provide the technology for Libya to build a major rail link between Sirte and Benghazi. Construction is expected to take four years.

Gazprom is also holding preliminary talks with Nigeria about a multibillion-dollar project to deliver Nigerian gas to Europe via a pipeline across the Sahara.

The project is costed at $10bn for the pipeline and $3bn for other installations, delivering up to 30bn cubic metres a year of gas to Europe. The 4,128km (2,580-mile) pipeline from Nigeria will cross Niger and Algeria.

Mr Putin said Libya "is orientated towards the most active co-operation with Russia in all areas".

President Putin is now in Sardinia for talks with Italian Prime Minister-elect Silvio Berlusconi. The Italian firm Eni is also involved in big energy projects in Libya and already has a close partnership with Gazprom.