I had a similar issue. Turned out to be a wire in the bundle that runs from the transom to the outboard motor.
Worst thing was it only happened when the motor was tilted at a certain angle.
Work your way from the trim motor back to each point, wire, and switch.