Philip, the Duke of Edinburgh, was admitted to the King Edward VII's Hospital on Feb. 16 after he felt unwell, to receive treatment for an unspecified, but not COVID-19-related, infection.
He was transferred briefly at the start of this month to a specialist cardiac centre at another London hospital, where he underwent a procedure for a pre-existing heart condition.
A Reuters witness said the duke left the King Edward hospital shortly after 10.30 GMT on Tuesday. There was no immediate comment from Buckingham Palace.
Since being admitted, the duke has been publicly visited only by his son and heir Prince Charles. The queen, 94, has remained at Windsor Castle, west of London, where the couple have been staying during the coronavirus pandemic, and has continued to carry out her official duties by video.
However, during his 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 his and Elizabeth's grandson Prince Harry and his wife Meghan.
During the interview, Meghan said a member of the royal family had made a racist comment while Harry criticised his relatives for failing to stand up to what he regarded as abusive press treatment of his wife.
Harry also 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 they had said, while Harry's elder brother William told reporters: "We're very much not a racist family".