Most likely due to a dirty/ faulty idle air control valve. If it is all gummy inside, the valve can’t open or close properly to maintain idle. This is usually mounted on the intake manifold near, or directly on the throttle plate area. Be advised that if you replace it, the first time you start it after replacing the engine may rev up to around 4,000 rpm until the computer kicks in to bring the valve closed, usually takes about 10 seconds.
×