Powering Motor shield and Arduino Mega Separately
On the side of the DC Motor Shield v1, there is an external power - +  2 pin terminal.

This can be used to supplement the shield with power.

Adafruit: "The motor controllers on this shield are designed to run from 4.5V to 25V.
MOST 1.5-3V MOTORS WILL NOT WORK"

If you are lucky to have the motor specs and ratings on hand, you will be able to account for how much power your motor(s) will need in your application.

Adafruit: "The motor driver chips that come with the kit are designed to provide up to 600 mA per motor, with 1.2A peak current. Note that once you head towards 1A you'll probably want to put a heatsink on the motor driver, otherwise you will get thermal failure, possibly burning out the chip."

Here is an important tid-bit for your scenario... (So no 9v Batteries for the motors!):

Adafruit: "You can't run motors off of a 9V battery so don't even waste your time/batteries! Use a big Lead Acid or NiMH battery pack. Its also very much suggested that you set up two power supplies (split supply) one for the Arduino and one for the motors. 99% of 'weird motor problems' are due to noise on the power line from sharing power supplies and/or not having a powerful enough supply!"

...

So makes sense,  get the Arduino powered, by itself, then get another power source for your motor shield.

Your sensors might be able to hop on the Arduino power supply if it's providing enough power.  I'd keep them separate from the motor power line, due to noise interference as suggested.

Try this, and see if the Arduino stays powered.

There is a lot of helpful info here, some new things I've learned just now.
https://learn.adafruit.com/adafruit-motor-shield/power-requirements