The pinion gear is the one on the motor. The bevel gear is the one in the mechbox the pinion gear engages. My guess is the motor height was set improperly which caused either the pinion or the bevel gear to wear over time. This is probably why it still worked for some time. Does it just do nothing when you pull the trigger or does it make a grinding sound?
Are you sure the pinion gear was the one that was worn? In my experience the bevel gear strips much faster than the pinion but I have never owned a KA M4. It was likely not a factory defect. You'll need new gears and seeing as you've already replaced the pinion, the bevel would be the next one to try but in all honesty, just get yourself a complete set of quality gears from Modify and they'll last forever.