The 48-year-old Romanian, who lives on the streets and in between shelters in Murcia, had climbed in after mistakenly thinking it contained clothing destined for recycling.
Police were called after passersby heard a man calling for help from inside a bin in the Vistabella neighbourhood.
He had managed to find his way in despite the container using a tilting door mechanism to stop people from raiding them, a practice that has reportedly increased during Spain’s prolonged economic crisis.
A local policeman said: “We just don’t know how he managed to climb in there.”
Officers at the scene were unable to free the man and had to wait for council workers to arrive and open the container.
He was freed after half an hour without injury.
Some 31% of Murcia are at risk of poverty, making it one of the poorest regions in the country.
Councils across Spain have begun locking their bins to prevent the surge of bin scavenging.