Sorry to have to tell you this, but it sounds like you have the so called 'death rattle'. If the car has a full BMW service history, you may be able to get it repaired as a goodwill gesture by BMW. However, I just noticed it's a D? I didn't think this issue affected the diesel engines. It needs to be checked and sorted, or the timing chain could snap and that would require a new engine.
It's a known fault with earlier petrol engines, especially in the S....as S & D are next to each other on the keyboard, I'm thinking you meant it's an S.
Do a google search for Mini death rattle.....they did put out a fix for it, but if you have to pay for it, then it will be expensive. There are also a whole load of youtube videos about it