A cam lock has a lock cylinder and a cam part connected to the lock cylinder. The cam part is turnable from a lock position to an open position when turning a key placed in the lock cylinder. The cam part comprises a spring and a flange that is arranged to receive external force towards the lock cylinder. The spring allows the movement of the cam part at the open position towards the lock cylinder as response to external force. The spring is further arranged to turn the cam part towards the lock position.