Britain's Duke of Edinburgh left hospital on Tuesday morning, after being admitted as a precautionary measure a month ago.
Prince Philip, 99, was recovering in the private King Edward VII's Hospital in central London, after heart surgery earlier this month.
He was admitted on February 16 after feeling unwell. The 28-day stay in hospital is the duke's longest period in hospital.
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," a statement said.
The palace did not disclose the initial reason for his admission but said it was not related to coronavirus.
Royal aides later said he was receiving treatment for an unspecified infection.
On March 1, he was moved to another London hospital, St Bartholomew's, where he had a successful surgery for a pre-existing heart condition.
He was moved back to King Edward VII's Hospital days later.
The duke, who turns 100 in June, left the hospital in the back of a black BMW.
Since being admitted, the duke has been publicly visited only by his eldest son Prince Charles.
Queen Elizabeth II, 94, has remained at Windsor Castle, west of London, where the couple have been staying during the pandemic, and has continued to carry out her official duties by video.
Both the queen and Prince Philip received their first Covid-19 vaccine dose in January.
The duke has required hospital treatment a number of times in the last decade for a recurring bladder infection.
At Christmas in 2011 he had an operation to clear a blocked artery in his heart after being rushed to hospital with chest pains.
During his latest hospital stay the royal family has found itself embroiled in its biggest crisis for more than two decades after the Oprah Winfrey interview given by Prince Philip's and the queen's grandson Prince Harry and his wife Meghan Markle.
During the interview, Ms Markle said a member of the royal family had made a racist comment about the couple's child, while Harry criticised his relatives for failing to stand up to what he regarded as abusive press treatment of his wife.
Harry said his father, Charles, had let him down and that he had felt trapped in his royal life.
The outpouring led Buckingham Palace to issue a statement on the queen's behalf saying she was saddened by what the couple had said, while Harry's elder brother William told reporters: "We're very much not a racist family".