The first things to check if is the adjustment of your rear derailleur. When you first assemble your bike, your derailleur may need to be tuned if you hear any noise as noted in the video below or if it is not shifting smoothly.
If your chain is coming off the largest diameter cog, this can be a serious issue and should be properly tuned before riding any further or avoid that gear until you can return home to adjust the derailleur. The bikes motor is so powerful, that if it continues to spin after the chain comes off, it can cause damage to the spokes or other components.
Rear derailleurs have 3 adjustment screws, plus the barrel adjuster at the derailleur and the barrel adjuster on the handle bars.
This video explains how to adjust your derailleur. If it the first time you are adjusting a derailleur, it may take some time to get it just right. It may need adjusted soon after riding as things settle (spring and cable tension).