The Duke of Edinburgh is retiring from royal duties this autumn, Buckingham Palace has announced.
Prince Philip, who turns 96 in June, made the decision himself and the Queen supported him, a spokesman said.
"I'm sorry to hear you're standing down", one man told him at a royal lunch on Thursday. "Well, I can't stand up much," the duke quipped.
The duke will attend already scheduled engagements between now and August but will not accept new invitations.
The Queen "will continue to carry out a full programme of official engagements", the palace said.
The duke carried out 110 days of engagements in 2016, making him the fifth busiest member of the royal family, according to Court Circular listings.
He is patron, president or a member of more than 780 organisations and will continue to be associated with them, but "will no longer play an active role by attending engagements", Buckingham Palace said.
In the statement, the spokesman said the duke "may still choose to attend certain public events from time to time".
Hours after the announcement, Prince Philip was at his 26th public engagement of 2017: a service and lunch for members of the Order of Merit at St James's Palace.
At the reception, the duke quipped to mathematician Sir Michael Atiyah that he "can't stand up much".
By Peter Hunt, BBC royal correspondent
This is Prince Philip acting on his own advice, nearly six years later.
When he turned 90 he told the BBC it was "better to get out before you reach your sell-by date".
From the autumn, he will follow a path into retirement which is trod by many non-royals once they are in their sixties.
Today's announcement is a significant moment in the recent history of the British Royal Family.
A prince of Greece - with Danish, German and Russian blood - he has served the ancient institution, very publicly, for seven decades.
As an outsider - who was viewed with suspicion by the aristocracy - he struggled at first.
To his critics, he is a gaffe-prone prince.
His many supporters argue that this nonagenarian senior royal has played a crucial role sustaining the monarchy.
It's little wonder then that the Queen once called him her strength and stay.
Broadcaster and writer Gyles Brandreth, a friend of the duke, told the BBC he had seen Prince Philip on Tuesday and could confirm his retirement was not on health grounds.
"I think he is retiring now in order to have a few years of retirement and I think the timing is thought through," he said.
"It's 70 years this autumn since he became the consort of Princess Elizabeth and then the Queen - so, after 70 years, I think he feels probably he has done his stuff."
BBC royal correspondent Nicholas Witchell said the duke - the longest-serving consort in British history - "clearly feels he now wishes to curtail" his "familiar role" in support of his wife.
The duke attended Lord's Cricket Ground to open a new stand on Wednesday and was heard joking at the event that he is the "world's most experienced plaque unveiler".
He is famed for off-the-cuff remarks he has made at royal engagements over the years.
Prime Minister Theresa May said she offered the country's "deepest gratitude and good wishes" to the duke and praised his "steadfast support" for the Queen.
Labour leader Jeremy Corbyn wished the duke "all the best in his well-earned retirement", saying: "His Duke of Edinburgh's Award scheme has inspired young people for more than 60 years in over 140 nations."
Prince Philip set up the awards in 1956 and they have become one of the UK's best-known youth programmes, with young people carrying out challenges to earn bronze, silver or gold awards.
Liberal Democrat leader Tim Farron said it was a moment to "celebrate and take stock" of the duke's "enormous achievements".
Scotland's First Minister Nicola Sturgeon said the "steadfast support" the duke had given the Queen was "hugely admirable".
Still on the diary
Buckingham Palace publishes details of official engagements up to eight weeks in advance. For the Duke of Edinburgh, these include:
- Visiting Pangbourne College, Berkshire, for its centenary - 9 May
- Presenting prizes at the Royal Windsor Horse Show - 14 May
- Attending a dinner marking the 70th anniversary of the founding of Pakistan - 18 May
- Visiting the Chelsea Flower Show - 22 May
- Holding receptions for young people who have achieved a gold Duke of Edinburgh award - 24 May
- Attending evensong to celebrate the centenary of the Companions of Honour - 13 June
- Presenting the Prince Philip Award at ZSL London Zoo - 27 June
- Hosting King Felipe of Spain during his state visit - from 12 July
US President Donald Trump is also due to make a state visit to the UK later this year, but no date has been announced for his trip.
The duke and the Queen celebrate their platinum wedding anniversary - their 70th - in November.
They have called a halt to long-haul travel in recent years, with younger royals carrying out those duties.
Royal commentator Dickie Arbiter said the duke is in "robust health", adding: "He is not giving up on life, just stepping [down] from full-time public engagements".
To date, the duke has:
- Carried out 22,191 solo engagements
- Taken part in 637 solo overseas visits
- Given 5,493 speeches
- Authored 14 books
Former royal butler Grant Harrold said: "I love his wit and I think people will miss seeing that on a day-to-day basis. But I don't think it's him disappearing, I think it's just him being very sensible, he's 95 years old.
"He's slowing down and I'm sure we will still hear and see of him from time to time."