I have an '88 Cherokee that has done that on occasion.
You might check the TPS (Throttle Position Sensor) on the throttle body. The TPS measures the angle of the throttle plate and produces a voltage which is sent to the engine controller to set the engine speed. The TPS follows to the throttle cable position, and over time, the variable resistor inside the TPS wears out and no longer provides a nice linear voltage response, but can have discontinuous voltage readings. When the voltage jumps erratically, engine RPMs can suddenly increase.
The TPS is an inexpensive part to replace ($22 to $40 at Rockauto.com), but you need a voltmeter to adjust its final position. A good repair shop should be able to install it in about 30 minutes.
I have replaced the TPS in my Cherokee at least 3 times in 145K miles - it just wears out. No big deal.
Do a search for " TPS Jeep Cherokee 4.0 engine " and you will find tons of info.