Margaret Thatcher was laid to rest on Wednesday with military pageantry and pockets of protests, in a funeral that reflected the polarising impact of Britain's longest-serving post-war prime minister.

Queen Elizabeth II led mourners from the British establishment and 170 countries in bidding farewell to the Iron Lady, who transformed Britain and is credited with helping end the Cold War.

Tens of thousands of people gathered to watch the procession through London to St Paul's Cathedral and many broke into spontaneous applause and threw flowers as the coffin passed by. But several hundred protesters turned their backs and booed at the cortege, proof of the bitterness that remains over Thatcher's legacy.

Britain's only female prime minister, who served from 1979 to 1990, died last week aged 87 after suffering a stroke. Her flag-draped coffin was transported through streets lined with 700 soldiers, sailors and airmen in full ceremonial uniform, carried first in a hearse and then in a World War I-era gun carriage drawn by six black horses.

Supporters say Thatcher's radical free-market reforms saved Britain from economic decline, but critics say they left millions of people out of work and created a culture of greed. The police deployed 4,000 officers for the funeral amid heightened security following the bombings at the Boston Marathon and fears of disruption by left-wing groups.

At one section of the procession, the applause was drowned out by chants of "Maggie, Maggie, Maggie! Scum, scum, scum!", although the protest passed off peacefully.

At the cathedral, the queen led the 2,300 mourners in a rare tribute - she had not attended a prime ministerial funeral since Winston Churchill died in 1965.

Prime Minister David Cameron, leader of Thatcher's Conservative party, joined politicians from across the political spectrum including former premiers John Major, Tony Blair and Gordon Brown.

Global figures including Thatcher's fellow Cold War warrior Henry Kissinger, the former US secretary of state, and showbusiness stars Joan Collins and Shirley Bassey also attended.

Sitting at the front were Thatcher's twin children Mark and Carol, 59, who had attached a note on the white flowers adorning the coffin which read simply: "Beloved Mother - Always in Our Hearts".

In his address, Bishop of London Richard Chartres acknowledged the debate that still rages over Thatcher's policies but said she deserved compassion at her funeral.

"After the storm of a life led in the heat of political controversy, there is a great calm," he said.

"The storm of conflicting opinions centres on the Mrs Thatcher who became a symbolic figure - even an -ism. Today the remains of the real Margaret Hilda Thatcher are here at her funeral service."

Many people had risen at dawn to travel to London for the funeral. "I wanted to pay my respects to the best prime minister since Churchill," said Gloria Martin, a property developer in her 60s with an array of "I Love Maggie" badges pinned to her chest.

"She was strong, she was resolute, and she put her country first above any idea of popularity."

The crowd included veterans of the Falklands war, viewed by many of her admirers as Thatcher's finest hour.

Servicemen from units that fought in the 1982 conflict with Argentina carried the coffin into St Paul's, while two brothers who served in the war walked behind.

The islands in the South Atlantic, which recently voted overwhelmingly to stay British in a referendum, held a day of mourning on Wednesday.

Argentina was pointedly not represented at St Paul's, where international guests included Israeli Prime Minister Benjamin Netanyahu and his counterparts from Canada, Italy, Poland and Kuwait.

A minute's silence was held for Thatcher at the United Nations headquarters in New York to coincide with the funeral.

The scale of the funeral - paid for with millions of pounds of public money - has sparked criticism from those who argue that she was too divisive to merit a state-funded send-off.

"We're spending £10 million (11.7 million euros, $15.3 million) on it and that's disgraceful and unacceptable at a time of austerity," said 22-year-old student Casper Winslow, one of those who turned his back to the coffin.

The protests took a more macabre turn in Goldthorpe in northern England, which like many of Britain's former mining communities was devastated by coal pit closures under Thatcher.

An effigy of the former premier was paraded inside an open wooden coffin before it was burned, while another hung from the roof of a social club, watched gleefully by drinkers outside.

The government has yet to disclose the costs of the funeral but insists it will be less than the reported £10 million.

Cameron insisted it was right to give Thatcher a proper farewell.

"It is a fitting tribute to a great prime minister respected around the world," he told BBC radio.

"And I think other countries in the world would think Britain got it completely wrong if we didn't mark this in a proper way."

The service was drawn up in line with Thatcher's wishes and included Christian hymns reflecting her strict Methodist upbringing, and Bible readings by her granddaughter Amanda and Cameron.

The former prime minister's coffin was later taken to Mortlake in southwest London for a private cremation. Her ashes are to be interned next to those of her husband Denis at the Chelsea Royal Hospital.