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".