MOSCOW -- Russia's president and political elite joined thousands of mourners on Monday in bidding farewell to Yevgeny Primakov, a former prime minister who also served as Russia's top diplomat and foreign intelligence chief during a long and distinguished career.

Primakov, who died last week at 85, lay in state in the House of the Unions, a columned building near the Kremlin where the state funerals of Vladimir Lenin, Josef Stalin and other Soviet leaders also were held. Among the mourners was 84-year-old Mikhail Gorbachev, the last leader of the Soviet Union.

State television covered the nearly six-hour funeral service live, with commentators and political figures commending Primakov for standing up to the West. He is remembered for his desperate but unsuccessful efforts to avert wars in Iraq and, as prime minister, NATO's 1999 bombing of Yugoslavia.

President Vladimir Putin said Primakov's ability to defend Russian interests was "an example of true patriotism and selfless devotion to the fatherland."

Putin noted Primakov's deep knowledge of the Middle East and his strong personal contacts with leaders in the region. "The role of Primakov here cannot be overstated," the president said in addressing the mourners. "His prestige abroad was undeniable."

Primakov entered politics in 1989, when he became chairman of one of the chambers of the Soviet parliament, helping spearhead Gorbachev's political reforms.

As the international drumbeat for war against Iraq increased in 1990, Gorbachev sent him as an envoy to Iraqi leader Saddam Hussein. Primakov was said to be the outsider whom Hussein knew best and trusted most.

In 1991, Primakov was named head of Russia's foreign intelligence service and held the job for five years before becoming foreign minister. As Russia's top diplomat, he worked hard to dilute the perceived U.S. dominance of world affairs.

After being appointed prime minister in 1998, Primakov tried to prevent the NATO air war against Yugoslavia over the Kosovo crisis. He was heading to the United States on an official visit in March 1999 when he learned that Washington had decided to launch the air raids, and ordered his pilots to turn the plane back while it was already halfway over the Atlantic, a bold move that helped bolster his popularity at home.

After Putin became president in 2000, he continued to tap Primakov's expertise in tackling global crises and made him Russia's top envoy to Iraq to try to stave off the brewing war in 2003.

Primakov also continued to wield considerable influence as the chairman of the Chamber of Industry and Commerce, a Russian business advocacy group, a post he held from 2001 to 2011.

He was to be buried in the Novodevichy Cemetery near the grave of Boris Yeltsin, Russia's first post-Soviet president.