I'm assuming the gun didn't just go off by pressing the slide release or working the action, so I have to assume the trigger was pulled and the safety was off.
For starters, review the owners manual for your firearm, if you do not have one you can download it from Mossberg's website. READ the manual.
Go out to the store or order online some dummy rounds for your shotgun and PRACTICE loading and unloading the gun safely.
Remember to keep your finger off the trigger, and better yet no-where NEAR the trigger, the lever on the Mossbergs is situated as such that you have no need to go near the trigger to press that lever.
This looks like a decent article on administrative manipulation of a Mossberg: Loading & Unloading A Pump Shotgun read it.
If you feel that there is a hardware problem (be honest with yourself, if you PULLED the trigger, it's not the gun's fault) with the firearm, take it to a smith or contact Mossberg for repairs.