The incident happened at Sandyhills, Dalbeattie, in Dumfries and Galloway at about 11:30am today.
Firefighters used specialist rescue equipment to reach the girl and release her in an operation that took about an hour.
She was taken to Dumfries Infirmary for treatment but is not thought to be seriously injured.
Coastguard and police also helped in the rescue in which firefighters used an inflatable "ice path" to make a safe passage to the girl and used a "sand lance" to pump water into the sand to allow them to release her.
The initial call to the emergency services said that two young people were stuck in the sand, but one managed to get free and tried to help the other before help arrived.
A spokeswoman for the Scottish Fire and Rescue Service said: "Fortunately the tide was out or it could've been more serious, the girl was up to her waist.
"We sent two fire engines and a rescue boat and used ice paths to make a path to and from the rescue scene, and a sand lance which makes the sand softer and easier to get the person out."