The device has a sterilization unit (2) comprising a bar-like body (4) that is insertable into an inner space of containers (10) through an opening of the containers. A moving unit produces a relative movement between the containers and the sterilization unit such that the bar-like body is insertable into the containers. A collision prevention device (20) prevents collision of the bar-like body with the containers and comprises a tubular contact body (22) that surrounds the bar-like body, where an inner cross-section of the contact body is larger than an outer cross-section of the containers. The moving unit is designed as a linear motor. An independent claim is also included for a method for sterilizing containers.