That is most probably a fuel pump gone bad. Google E46 1/4 tank problem, same principle
I had this problem on my E46 and everytime I get to the 1/4 tank mark the car will shake and then backfire and eventually stop/die. After refill the car will drive like nothing happened.
I replaced the fuel pump and problem vanished :rollsmile: