When you pull the trigger, it releases the firing pin. That pin hits the primer, which ignites the gun powder in the shell and shoots the bullet. The gas released from the miniature explosion propels the shell backwards.
A 3D animation created in Cinema 4D and After Effects showing how an AK-47 rifle works. Corona renderer was used in order to create realistic materials and reflections.