Image copyright PA Image caption The Red Arrows flew overhead, exactly eight centuries after the ground-breaking accord

Magna Carta went on to change the world, Prime Minister David Cameron has said, at an ceremony in Surrey marking the 800th anniversary of the document that heralded modern democracy.

The event at Runnymede, where King John sealed the original accord in 1215, was attended by the Queen and other royals.

The Duke of Cambridge unveiled a commemorative art work at the site.

The charter first protected the rights and freedoms of society and established that the king was subject to the law.

Image copyright PA Image caption Representatives of the Church, government and monarchy attended the event in Surrey

Image copyright Getty Images Image caption Princess Anne re-dedicated the American Bar Association memorial, erected at the site in 1957

Image copyright PA Image caption The Duke of Edinburgh and the Duke of Cambridge were among guests

Image copyright AP Image caption The Queen did not give a speech but wrote in the programme for the celebration that the Magna Carta's principles were "significant and enduring"

The Duke of Edinburgh and the Princess Royal also attended the ceremony, along with the Archbishop of Canterbury, senior judges, US Attorney General Loretta Lynch and members of the American Bar Association, which erected a memorial to the charter at Runnymede in the 1950s.

Magna Carta originated as a peace treaty between King John and a group of rebellious barons.

Its influence can be seen in other documents across the world including the UN Universal Declaration of Human Rights, and the US Constitution and Bill of Rights.

Speaking at the Magna Carta Memorial, Mr Cameron said the document had inspired different generations and countries.

He said it had had altered forever "the balance of power between the governed and the government".

"Why do people set such store by Magna Carta? Because they look to history. They see how the great charter shaped the world, for the best part of a millennium, helping to promote arguments for justice and for freedom."

He also alluded to the government's plans to replace the Human Rights Act with a British bill of rights, amid its concerns about rulings by the European Court of Human Rights and their application to the UK.

Mr Cameron said in his speech: "It falls to us in this generation to restore the reputation of those rights... It is our duty to safeguard the legacy, the idea, the momentous achievement of those barons."

The Archbishop of Canterbury, the Most Reverend Justin Welby, said the document had "set the bar high for all of us today".

In his address, he reminded the audience how his medieval predecessor Archbishop Stephen Langton played an important role as a mediator in the writing of the Magna Carta.

He also said the Church had failed to support the fight for social justice in the past.

"From the support for enclosures to the opposition to the Great Reform Act, to the toleration of all sorts of abuse, with humility, we recognise these failings," he said.

Analysis

Image copyright Reuters Image caption Soldiers stood guard at the American Bar Association's Magna Carta Memorial

Peter Hunt, BBC diplomatic and royal correspondent

For a document credited with delivering so much, this was a brief celebration, limited to a few speeches and musical performances.

Where powerful rebellious barons and a king had once sealed Magna Carta, sat a Queen whose powers and those of her many ancestors were limited by the 800-year-old text.

The Latin text, written on sheepskin, failed to avert a civil war.

Today, in the meadow by the River Thames, the prime minister used it to highlight a future battle - the one to come over his government's plans to replace the Human Rights Act with a British Bill of Rights.

Reform, which will be contested, is for the future.

Today, the focus was more on the past and celebrating Magna Carta, which is revered and has had influence in America and at the United Nations; and which is considered by many to represent the foundation of democracy.

Read more from Peter

Lord Dyson, Master of the Rolls and chairman of the Magna Carta Trust, said the Magna Carta was "a symbol of democracy, justice, human rights and perhaps above all the rule of law for the whole world".

Lord Dyson, the second most senior judge in England and Wales, said: "A few clauses of Magna Carta are still part of our law, including famously the provision that no free man shall be taken or imprisoned except by the lawful judgment of his peers or by the law of the land; and to no-one will we sell, to no-one will we deny or delay right or justice."

Media playback is unsupported on your device Media caption Hew Locke's installation of bronze chairs will be unveiled in the meadows

The art installation unveiled by Prince William, called The Jurors, is inspired by the 39th clause of Magna Carta, which gives the right to a jury trial. Artist Hew Locke said it was a "great honour" to be chosen to produce the piece.

Why is Magna Carta so important?

Image copyright Getty Images Image caption Magna Carta was first agreed by King John on 15 June 1215

By Clive Coleman, BBC legal correspondent

"Does Magna Carta mean nothing to you? Did she die in vain?" asked an exasperated Tony Hancock playing the jury foreman in an episode of his Half Hour.

Clearly not. Far from dying, Magna Carta has had a life longer, fuller and more influential than the most optimistic medieval baron could have imagined.

But why is a charter from 1215, which was declared null and void by the Pope within weeks of being written, which doesn't mention "trial by jury" or "habeas corpus" (the right not to be held indefinitely without trial), and which forbids any woman from accusing a man of murder or manslaughter, seen as the foundation of our liberties and our law?

At its heart is the idea that the law is not simply the whim of the king, or the government.

It is the great egalitarian legacy of Magna Carta, that all are equal under the law, and all can be held to account.

It is that idea that gave birth to so many of our rights and freedoms, to parliamentary democracy, fair trial, and a series of controls on the abuse of arbitrary power.

Princess Anne rededicated the US memorial, saying Magna Carta "provides us with one of our most basic doctrines - that no person is above the law.

"In recent history and even today we see in many parts of the world that power without the rule of law can lead to human suffering of terrible proportions. But it takes all of us to stand up for these principles."

A replica of Magna Carta began its journey down the Thames on Saturday as part of the commemorations.

The Royal Barge Gloriana led 200 boats from Hurley in Berkshire to Runnymede.

Image copyright PA Image caption The Royal Barge Gloriana has been leading a flotilla along the River Thames to mark the anniversary

Image copyright Reuters Image caption Prince William was shown an art installation commissioned to mark the anniversary

There are just four known copies of the original Magna Carta in existence today, from an estimated 13 that were made.

Two are held by the British Library, with Salisbury Cathedral and Lincoln Cathedral holding the others.

Media playback is unsupported on your device Media caption Magna Carta was sealed 800 years ago today

What was Magna Carta?

Image copyright Getty Images

Magna Carta originated in 1215 as a peace treaty between King John and a group of rebellious barons

The original document was written in Latin on parchment made from animal skin

The name didn't emerge until the document's reissue in 1217

It became known as The Great Charter to differentiate it from the smaller Charter of the Forest issued at the same time

BBC iWonder - How did a peace treaty from 1215 forge the freedoms of 2015?