"He is in good spirits," a royal source says, noting the spring in the step of the Duke of Edinburgh, 92, as he left the clinic with a book under his arm. "He practically ran out of there."
He headed to Windsor Castle, where the Queen, 87, is based for a week of events, beginning with the Order of the Garter ceremony and then several days' horseracing at Royal Ascot.
Philip, who spent his birthday in the hospital last week, was admitted to the London Clinic June 6, for an "exploratory" operation on his abdomen. Palace sources had said he was expected to stay for up to two weeks.
A spokesman tells PEOPLE that Philip will be convalescing for the next two months and plans to resume his royal duties in the fall.
"He has expressed his thanks to the medical staff at the London Clinic and the many members of the public who have sent him good wishes."
Philip received about 1,000 cards and letters, a source says. The Queen, as well as his grandchildren, including Prince William and Prince Harry, paid Philip visits in the hospital.
Later Monday, Philip was not at his wife's side as she led a procession through the grounds of Windsor Castle for the annual Order of the Garter service.
In a break with tradition, she was instead flanked for the walk to St. George's Chapel by her especially attentive son Prince Charles and her grandson Prince William, both in velvet gowns and plumed hats.