2005 Nissan Pathfinder losing power while driving

My 2005 Nissan Pathfinder with approximately 150,000 miles has been losing power while driving. It’s pretty scary. The problem first manifested one week ago when it stalled at a stoplight. It restarted after a few panicky moments of frantic key turning. My husband and his identical twin brother took a look under the hood when I got home and discovered the terminal on the battery was loose and had a screw in it to maintain a closer fit. They remedied that by replacing the screw with aluminum foil. Four days later, I’m driving away from a large big-box store, and it loses power again. I got it restarted and drove around back of the store to the tire center. They tested the battery, and declared it “bad”. The battery and the terminals were replaced. Hooray! I was safe. Or so I thought. The very next day, I drove out to the middle of nowhere to go fishing, and it lost power three times. I was an hour away from home and there was no cell phone service. I left the lake before dark and lost power once more on the way home. To recap, the first time it lost power I was stopped at a light, the second time (at the store) I was at a stop sign, the third, fourth, and fifth times I was driving but slowing down for cars in front of me and had to pull over to restart it, and the last time I was driving down hill and the power came back on before the bottom of the hill. A lot of lights come on in the dashboard when it loses power. Any ideas what the issue could be?

Wild guess . . . you have a bad connection somewhere

Or perhaps some module has a bad solder joint, which is opening up when it gets warmed up

Check clean and tighten the grounds to the engine and chasis. It could also be a bad ignition switch.

I would still suspect a battery cable problem at the outset. All terminal replacement parts are not created equal nor are all installers. Personally, I would just replace the main cables altogether - they are 10yrs old and whatever was up with the loose terminal and tin foil is just bad all around. But if someone else would do this and it would cost a lot or they would use cheap cables or something, starting with cleaning the grounds as knfenimore suggested is the right thing. And I would include the positive connection at the main power junction box under the hood.

I’m going on a separate track of thought. It seems the stalling occurs when your foot is on the brake. I’ve seen this before, and it was a brake booster that leaked when the pedal was pressed, causing a large vacuum leak at idle that causes the engine to stumble and stall. This can be replicated in the driveway by simply pressing the brake and seeing if the engine stumbles. In both casrs I’ve seen, you can also hear the leak under the dash.