Try a Diesel purge
Get a couple of cans of Diesel purge and check this board for how to use it to clean those injectors.
It's a Diesel engine and so we can rule out the spark. (As Alex's sticker says, Diesels have been spark-free since 1892)
So the problem is related to either air or fuel delivery. Of course, (heaven forfend!) it could be due to a faulty signal from the computer regarding the fuel delivery as well.
The Diesel purge won't cost much and can't hurt. You might take a look at your air filter, it could also be dirty. There are several ways that something could cause it to suck in oil and therefore not deliver the air your engine needs.
Injectors do not last forever and there might be one or two that need to be replaced.
There are others who are professionals that know more than I do. I am an expert, but in linguistics, not Diesel engine diagnosis and repair.
Nonetheless, I am sincere and that is my best shot.
To get better advice, try a new message, with the title "87 300TD stalls annoyingly" or something like that. This will attract mechanics more effectively, I think.
Semibodacious Transmogrifications a Specialty
1990 300D 2.5 Turbo sedan 171K (Rudolf)
1985 300D Turbo TD Wagon 219K (Remuda)
"Time flies like and arrow, yet fruit flies like a banana"