Five tugboats were sent to free the 70,000-ton ship.
"She touched a sandbank called Brambles, but with the tide rising she was able to get away," a spokesman for Cunard, the ship's owner, told reporters. "We are not aware at this stage of any damage to the vessel and everything is proceeding today as planned."
The Duke of Edinburgh led a ceremony later on Tuesday morning, during which 1 million poppies were dropped onto the ship by a Tiger Moth plane, to mark the 90th anniversary of the end of World War I.
The QE2, launched by Queen Elizabeth II in 1967, has covered 5.5 million miles in more than four decades of service. After docking in Dubai on November 26, it will be converted into a luxury floating hotel.
Tickets for the final voyage of one of the world's most famous ocean liners were sold out, with the most expensive costing over $44,000. The ship will leave Southampton for Dubai on Tuesday evening.