Same thing happened to me after an offroading trip where I went through deep water. Everytime I pressed the brake pedal engine would rev up, algo everytime I put it in Park engine would rev up.
Also If I turned the lights on engine would rev up until I turned them off.
Pretty sure it was a wet sensor, It stopped doing that a couple of days later. My guess, the sensor dried.