Why do externalities lead to a Pareto-inefficient outcome?
If you allow side payments then the issue you identify goes away in a Coase sense.

The citizens being polluted could pay for production to be reduced by one unit.  This amount would have to be between the benefit of the reduced pollution and the loss to the pharmaceutical firm from the reduced production. But this last figure is small: at the competitive equilibrium the firm is matching its marginal revenue with its marginal cost so its profit from the final unit of production is very small, while presumably the pollution effect is larger (if not then the competitive equilibrium is already efficient). 

So the position with the side payment dominates the position without it in a Pareto sense, as both the citizens and the pharmaceutical firm are better off.  Possibly further side payments and production reductions would be even more efficient, at least until the marginal profit loss exceeds the value of reduced pollution; that point is then Pareto optimal and the starting point was not. 

You may have to extend this slightly as the reduction in production also affects the customers of the pharmaceutical firm, who see a reduction in consumer surplus from the lower production. But again, side payments from the citizens to the customers can move to a Pareto optimal position, until the marginal value of the reduced pollution equals the combined marginal losses of the pharmaceutical firm and its customers.

Advocates of the "polluter pays principle" would describe this as unfair, but Pareto optimality does not judge fairness.  Another practical issue would be creating a mechanism which avoids free-riding and leads to an efficient agreement, a frequent issue with Coasian bargaining.