Sounds similar to what my wife's 2003, 325 did.
Turned out that a wiring harness was routed too close to a header. When it
heated up, the signal to the computer got mixed. After a few minutes of
cooling, ... off it went.
Re-routed the harness, & it's bee fine ever since.