Prince Philip, 99, was admitted to King Edward VII's hospital in central London on 16 February after feeling unwell.
He later underwent a successful procedure for a pre-existing heart condition at another London hospital - St Bartholomew's.
The duke has now returned to Windsor Castle.
In a statement on Tuesday, Buckingham Palace said the duke was discharged "following treatment for an infection and a successful procedure for a pre-existing condition".
"His Royal Highness wishes to thank all the medical staff who looked after him... and everyone who has sent their good wishes," the statement said.
Prince Philip left through a side entrance of the hospital in a wheelchair and was helped into the rear passenger seat of a waiting car.
Speaking during a visit with the Duchess of Cornwall to a pop-up vaccination centre in London, Prince Charles, who visited his father during his stay in hospital, told reporters it was "very good news" and he was "thrilled" that his father had gone home.
He also confirmed that he had spoken to the duke.
Prime Minister Boris Johnson "continues to wish Prince Phillip a speedy recovery," his spokesman said, adding the PM was "of course" pleased to see the duke return to Windsor.
Prince Philip and the Queen, 94, have spent the most-recent lockdown in England living at the Berkshire residence with a small group of household staff, nicknamed HMS Bubble.
The couple, who have been married for 73 years, received their first Covid-19 jabs in January.
The exact reason for his initial admission to hospital was not disclosed, but the Palace said at the time it was not related to coronavirus.
After being admitted to King Edward VII hospital, Prince Philip was transferred to Barts for specialist treatment and underwent a heart operation on 3 March.
He later returned to King Edward VII's hospital - a private clinic which has treated the Queen on several occasions as well as the duke and other senior royals.
Members of the Royal Family continued with their official duties during his 28-night stay - his longest-ever in hospital.
The duke, who retired from royal duties in 2017, has received treatment for other health conditions over the years, including a bladder infection in 2012 and exploratory surgery on his abdomen in June 2013.
She also attended numerous virtual meetings, including with scientists, members of the armed forces, Chancellor Rishi Sunak, and kept up her weekly audience with Mr Johnson via telephone.
Prince Philip's hospital stay coincided with the Duke and Duchess of Sussex's interview with Oprah Winfrey, in which allegations of racism and a lack of mental health support were levelled at the Royal Family.
Buckingham Palace said in a statement afterwards that the issues were concerning, and while "some recollections may vary", the matter was a family one that will be dealt with privately.
In the interview, Meghan told Oprah that she phoned the monarch directly "just to check in" after hearing the duke had been taken to hospital.
US TV presenter Gayle King said on Tuesday that she had spoken to the Duke and Duchess of Sussex and was told discussions between Harry and his brother, Prince William, and father, Prince Charles, were "not productive".
Ms King told CBS This Morning that despite the talks not bearing fruit, the couple were "glad" that conversations had begun.
She added: "I think what is still upsetting to them is that the Palace keeps saying they want to work it out privately, but yet they believe these false stories are coming out that are very disparaging against Meghan still - no one in the Royal Family has talked to Meghan yet."
Buckingham Palace has declined to comment.