The Duke of Edinburgh spent 28 nights as an in-patient - his longest ever stay - after he was admitted on 16 February.
He was initially taken to King Edward VII’s Hospital after feeling unwell at Windsor and was moved to St Bartholomew’s Hospital in the City of London two weeks later.
He underwent surgery for a pre-existing heart condition at St Bartholomew's on 3 March, before being transferred back to King Edward's to recover and continue treatment.
The duke left the private hospital in the back of a black BMW on Tuesday morning. Buckingham Palace later issued a statement confirming his release.
“His Royal Highness wishes to thank all the medical staff who looked after him at both King Edward VII's Hospital and St Bartholomew's Hospital, and everyone who has sent their good wishes,” the palace said.
Philip has been treated for heart problems in the past and in 2011 was rushed to hospital by helicopter from Sandringham after suffering chest pains as the royal family was preparing for Christmas.
In the serious health scare, he was treated for a blocked coronary artery at Papworth Hospital in Cambridgeshire and underwent a minimally invasive procedure of coronary stenting.
The duke was visited in King Edward VII's Hospital on 20 February by his eldest son, the Prince of Wales, who made a 200-mile round trip and stayed for around 30 minutes.
While the duke was recovering the monarchy was plunged into crisis following shocking allegations of racism made by Prince Harry and Meghan Markle in an interview with Oprah Winfrey.
The Duke and Duchess of Sussex, who faced calls to postpone the interview because Philip was unwell, accused an unnamed royal - not the Queen or the duke - of raising concerns about what colour their son Archie’s skin tone would be before he was born.
Ms Markle also spoke about how she begged for help when she was suicidal, but said the institution gave her no support.
The Queen, 94, said the issues were concerning, but that "some recollections may vary" and the matter was a family one that would be dealt with privately.
Philip has spent most of lockdown at Windsor with the Queen for their safety, alongside a reduced household of staff dubbed HMS Bubble.
The couple received their first Covid-19 jabs in January.
Join our new commenting forum
Join thought-provoking conversations, follow other Independent readers and see their replies