The engine should fit, but it I am taking a guess. It used to come as 535i and those engines are quite big. However, there is no way any E12 gearbox will handle the torque from the big diesel. So the gearbox will have to go in as well. There may be issues about the size of the box and the E12 floorpan. The torque thing applies to the rest of the driveline as well, so the driveshaft, diff, halfshafts etc. will have to be examined for suitability as well. The E12 diff would probably have the wrong ratio as well.
After fitting it, the next challenge will be to get the engine management system talking to the rest of the car. The diesel engine CPU is programmed to speak the CPU inside the car's key. That means that the E12 will need to have a modern key. However the doorlocks used a very different key. I had a 520 manual E12 (carburettor model) and the key was just an old fashioned thing.
After overcoming all this, you will then have a very fast car with 1970s brakes. Depending on what car you start with, you might even have drum brakes at the rear, like my 520 had. So the brakes will need an upgrade as well.
And then comes the suspension. Even if you fit all the latest gas shocks, it will still be 1970s tech. The E12 was somewhat notorious for tail happy handling, even back then. With a modern turbodiesel moving the car, it would not be for the faint of heart.
But don't let me talk you out of the idea. It can certainly be done.
As an aside, those drum brakes and tail happy handling meant that the E12 did wonderful handbrake turns. But I never said that. How would I know anything about that?