The Duke of Edinburgh bounced back after undergoing a minor procedure on his right hand by quipping with staff at a family planning centre "at least you are all legitimate".
Philip made the joke as he opened the new Margaret Pyke Centre in King's Cross, central London, today.
Mike Waddington, the communications chief for Central and North West London (CNWL) NHS Foundation Trust which operates the clinic, said staff were left in fits of giggles after the one-liner.
Asked about the quip, he said: "Yes he did say that, but it was all very, very good natured.
"It came just after the speech about the association. The Prince got a big round of applause and his response was to say that joke, and he got another laugh with that."
The Duke was in high spirits despite having undergone a "minor procedure" performed at Buckingham Palace the day before which left him sporting a bandage.
It is the third time Philip, 92, famed for his sense of humour, has opened the centre in its 45-year history.
He also unveiled a plaque at the clinic, which has just moved into a newly revamped building and provides sexual and reproductive healthcare for visitors who come from 130 towns across the country.
Mr Waddington said the Duke, who unveiled a plaque at the centre, chatted away to staff during the visit.
He said: "He was just very interested in everything - about the building, the staff. He wanted to meet the reception staff, he was very interested in them."
CNWL's chief executive, Claire Murdoch, said: "We are very honoured that Prince Philip agreed to officially open the Margaret Pyke Centre.
"The centre has an established international reputation for quality research and clinical excellence and training in the field of sexual and reproductive health, while providing great patient-centred care and treatments."
Mark Burrell, chairman of the Margaret Pyke Trust, said: "We are delighted that His Royal Highness has agreed to officiate once more - he is a valued part of the Margaret Pyke Centre's history.
"Margaret Pyke was a contraception advocate and family planning pioneer. She was, together with her pioneering colleagues, an effective promoter for the right of women to have access to contraception, and contributed to its eventual inclusion in main stream health care."
Buckingham Palace declined to give further information about the procedure the Duke had undergone.
Philip arrived at a garden party at the Palace with the hand in a bandage, where g uests were impressed that he was continuing with his engagements.
Classically trained rock musician Rick Wakeman, who is King Rat in the Grand Order of Water Rats, which helps widows and families of people in the entertainment industry, said: "He shook my hand as normal. I've been lucky enough to meet him a few times, and he's always been on fine form.
"I just find the pair of them amazing. I'm openly a huge royalist, so proud of everything they do. I don't know where they get their energy from."
Lauren Ellis, 24, from Putney, south west London, who runs a company which organises student events to raise money for charity, said: "He shook hands with me and my sister and he did grip my hand, so he must be able to move it OK.
"It's brilliant that he's carrying on with his engagements."
Her sister, Darea, 27, a solicitor from Esher, Surrey, said: "You can tell that he has quite a lot of vitality. He seemed fun."
The Queen wore a matching lavender coat and dress designed by Angela Kelly for the first garden party of the season, which was attended by about 8,000 guests.