He waved to nurses and doctors who lined the steps of the hospital as he left in the front passenger seat of a Range Rover.
Prince Philip headed home the day after the Queen listened to prayers for him as she attended a service at Crathie Kirk without her husband.
He was admitted to Aberdeen Royal Infirmary on Wednesday after becoming unwell on his annual summer break to Balmoral with the Queen.
The sovereign attended morning mass on Sunday with Prince Charles, the Duchess of Cornwall and the Earl and Countess of Wessex.
She listened as the Reverend David Cameron wished the Duke of Edinburgh a speedy recovery and quick return to his holiday.
Doctors said the Duke needed complete rest – and asked that he didn't receive visitors.
The Queen, pictured on the car jouney home from church, received regular phone updates on his health while she waited in Balmoral, 50 miles away.