Talk about pulling the rug from underneath...

A Homeless man in South Portland was near a bank A-T-M when the machine malfunctioned and started to uncontrollably spit out cash...about 37-thousand dollars worth!!!

A woman waiting to use the machine had called cops, and they found the guy stuffing money into shopping bags.

The cash ended up being returned.

The bank doesn't plan on pressing charges.

(Photo: CBS 4)