Car kept going slower and slower until it went 2mph. But wouldn't die. on 2001 BMW 525i

Check engine indicator light is on. I thought I was out of fuel as was running on fumes. When I added more fuel the next day it ran fine for 15 mins then the same thing happened.

Asked by for the 2001 BMW 525i
You need to get the car's stored code first. Diagnose from there. Could be anything from fuel filter, fuel pump, vacuum leaks, never been tuned up, etc...
Thanks Hal