The game engine has been designed for the behind team to foul the weakest FT shooters from the other team in desperation time, and also to bring in the best 3 point shooters.
It is somewhat trickier for the team that is ahead since atrocious FT shooting might be compensated for with strong OD. If the coach brought in a better FT shooter, the losing team will foul someone else, and might get relative easy 3 pointers.