There are several possible causes for the behavior. Please take each of the following steps that you haven't already tried until it's resolved. Some may not apply in your case.
1. Follow the instructions in this support article, and also this one, if applicable. A damaged or defective AC adapter could be the cause, even if it's the right kind.
2. Press down all four corners of the trackpad at once and release. If there's any effect, it's likely to be temporary, and in that case the unit must be serviced or replaced.
3. Disconnect or power off each Bluetooth or USB pointing device, one at a time, testing as you go. You may be able to identify one that's malfunctioning. By a "pointing device," I mean a peripheral that moves the cursor, such as a trackpad, mouse, trackball, or graphics tablet. A plain keyboard is not a pointing device. If you have a desktop model without a built-in trackpad, at least one external pointing device must be active at all times.
4. If your model has an infrared receiver for use with an Apple Remote, disable it.
5. This step applies if you're using a portable Mac with a built-in trackpad, and you also use an external mouse or trackpad. Open the the Accessibility pane in System Preferences and select Mouse & Trackpad from the menu on the left. Check the box marked
Ignore built-in trackpad when mouse or wireless trackpad is present
Credit for this observation to ASC member PattMK.
6. Reset the System Management Controller.
7. If you're using a Bluetooth trackpad or mouse, investigate potential sources of interference, including USB 3 devices.
8. A swollen battery in a portable computer can impinge on the trackpad from below and cause erratic behavior. If you have trouble clicking the trackpad, this is likely the reason. The battery must be replaced without delay.
9. A defective peripheral device or a damaged cable can cause the built-in trackpad of a MacBook to behave erratically. If you're using any wired peripherals, disconnect them one at a time and test.
10. There's also a report of erratic cursor movements caused by an external display that was connected but not turned on.
11. If you use Handoff, disable it in the General pane of System Preferences.
12. If AirPlay mirroring to a TV is on, turn it off.
13. If none of the above applies, or if you have another reason to think that your computer is being remotely controlled, remove it from the network by turning off Wi-Fi (or your Wi-Fi access point), disconnecting from a Bluetooth network link, and unplugging the Ethernet cable or USB modem, whichever is applicable. If the cursor movements stop at once, you should suspect an intrusion.
14. Make a "Genius" appointment at an Apple Store to have the machine and/or external trackpad tested.