Prince Philip made the public appearance alongside several members of the royal family ahead of the service at Crathie Kirk church.
Zara and Mike Tindall, who welcomed their second daughter in June, accompanied the Queen, 92 and Prince Philip, 97.
Prince Edward, Sophie Wessex and their 14-year-old daughter Lady Louise also attended the service.
The Duke of Edinburgh is said to have surprised the Queen with his arrival on Royal Deeside.
He has been fishing and hunting during the royals' summer break at Balmoral and is "fit as a fiddle," according to the Sun.
Philip underwent a hip replacement in April. He was described as being "in good spirits" after the operation.
The Queen usually spends her summers in Balmoral.
The last time Prince Philip made a public outing was for the Royal Windsor Cup polo match in Egham in June.
Philip retired from public life last August. Buckingham Palace said he would attend events from "time to time."
Prince Harry and Meghan Markle, the Duke and Duchess of Sussex, are also expected to visit Balmoral this summer.