Car lurching and lights flickering

When I turn on my car the interior and exterior lights dim slightly and then brighten and dim again. This happens repeatedly and as you see the the lights flicker your can feel the car lurching in rhythm with the lights. When I let up of the brake the car does not coast like it should but slowly lurches. The car has no problem turning over, and if you push on the gas pedal the lurching and flickering stops. What do you think is wrong?

Year and mileage?

I would have the alternator and the battery tested. Many parts stores will do this free. The alternator may be failing. I’d also inspect major electrical connections, including grounds, for dirt, corrosion, or loose connections.