A 33-year-old woman parked her car outside a supermarket in Ludwigshafen, Rhineland-Palatinate, on Thursday and gave the car keys to her nine-month-old baby to play with temporarily, police said on Friday.
But as she was getting out of the car, the door accidentally shut - by coincidence at the same time that the infant hit the button on the key ring to lock the doors, shutting the mother out and the baby inside.
The mother tried to find a way to open the door, but called police when her attempts failed.
At the behest of the mother, officers smashed in the car window to retrieve the baby - and the car keys - from inside.
Given that it was 37C outside at the time, the baby was taken to hospital as a precautionary measure.