The army's emergency unit UME said it sent two companies of specialist soldiers and 95 vehicles to free over 3,000 vehicles that became stranded on the AP6 highway linking Madrid and the northwestern city of Segovia.
"The vehicles were removed one by one.
There were cars with babies inside that did not have water or food," said UME spokesman Aurelio Soto.
Videos posted on Twitter by emergency services showed soldiers and police battling snow drifts as they used shovels to clear snow from around trapped cars.
About 70 kilometres of the highway in the centre of the country were blocked by snow just as families were returning home after the end of the Christmas holidays.
Motorists took to social media to complain that they had been trapped on the road since Saturday night without anything to eat and no heating, amid freezing temperatures.
My husband and I didn't eat anything to give the little we had to our children," Sara Ramos, who was trapped in her car for 15 hours with her husband and two children aged two and six, told Spanish public television.
"It was really distressing because it was many hours of waiting.
It was a really difficult situation.
There were people who had no heat because their car battery ran out."
Public Works Minister Inigo de la Serna said the government had opened an inquiry to see if the toll road operator that runs the AP6 highway - Iberpistas, a subsidiary of Spain's Abertis - "had fulfilled all protocols" for a snowstorm.
The minister said many other roads were covered by snow but these were closed and cleared without drivers being trapped in their vehicles for so long.
He urged people not to use their cars in areas affected by the snowstorm "unless it is strictly necessary".
Spain's weather office issued alerts for 37 provinces on Sunday because of the risks posed by the heavy snow, strong winds, and rain.