I had the same problem and it drove me nuts because it was intermittent. I replaced the fuel filter and the PTO switch but the problem persisted. I finally found that the ground wire, which runs directly off of the battery to the engine base, was loose where it is attached to the engine and frame. The nut is very difficult to get to. I finally got a 1/2" box end wrench on the nut at the base of the engine but there was not enough room to turn the nut. So, I had to lift the mower and tighten the bold from under the frame and use the box end wrench on the top to keep the nut from turning.
Runs great now!