The Queen had been at London’s King Edward VII’s Hospital since Sunday – her first hospital stay in 10 years.
All official engagements for this week, including a visit to Rome, were either cancelled or postponed. She also missed St David’s Day celebrations in Swansea.
Buckingham Palace said Queen Elizabeth, 86, was admitted as a precaution and was otherwise in “good health”.
On Monday afternoon, a Bentley took the Queen to Buckingham Palace, where she will spend the night.
Dressed in a red coat and smiling, the Queen shook hands with hospital staff on the steps outside.
A Palace spokeswoman confirmed the Queen’s diary for this week would remain suspended.
She said: “Engagements cancelled or postponed this week remain so.
“Next week, we’ll have to see, as she has only just been released from hospital.”
On Saturday, the Queen had missed the military ceremony in Wales due to the stomach bug.
On Sunday, the Queen was driven from Windsor Castle, where she had been resting, after carrying out a private medal presentation earlier in the day.
A spokesman for the Queen said she was in “good spirits” and her admission was “a precautionary measure”.
Gastroenteritis causes inflammation of the stomach lining and intestines.
The infection can be transmitted through contact with an infected person or contaminated food and drink. Symptoms can include vomiting, fever and stomach ache.
The Queen’s treatment, which has not been disclosed, may have included rehydration and tests to establish if the illness was caused by an infection or an underlying problem.
The Queen last received treatment 10 years ago, again at the King Edward VII’s hospital, for a minor knee operation. At the same time, surgeons removed minor, non-cancerous lesions from her face.
Next weekend, she had been due to spend two days in Rome with the Duke of Edinburgh, at the invitation of Italy’s President Giorgio Napolitano.
It is not clear whether the visit will be re-scheduled.
A reception at Buckingham Palace on Tuesday for MPs and MEPs will go ahead with other members of the Royal Family present.
RDE-LHffrDcImage source: Wikimedia Commons President-elect Donald Trump celebrated his election victory at the Ultimate Fighting…
Millions of voters across the US chose to return Donald Trump to the White House…
Donald Trump declares victory in the US election as he addresses jubilant supporters in Florida.…
Stocks around the world are rising as Donald Trump appears to be on the cusp…
Donald Trump has won Pennsylvania, North Carolina and Georgia and taken a lead over Kamala…
Quincy Jones, the celebrated musician and producer who worked with Michael Jackson, Frank Sinatra, Ray…