The check engine light comes on and the motor bogs down. Why is this? on 1993 Toyota Pickup

The motor is a 22R. If you turn the truck off while the engine light is on the starter will not work, only a click. If you turn the truck off when the engine light is off the truck will start just fine. I had the starter checked, replaced both ground wires, positive wire to starter, starter relay, and cable ends. When the light is off the truck has good power. I can drive a few miles just fine, then the light comes on and I lose power. A few blocks later the engine light goes off and the engine is normal again for 5 or 10 miles. Also replaced fuel filter.

Asked by for the 1993 Toyota Pickup
have codes ck'd and post so we can adv