In a setback to Actavis, a federal court judge has issued a preliminary injunction that prevents the drug maker from pulling an older version of its Namenda medication for Alzheimer’s from pharmacy shelves.

The ruling comes three months after the New York state attorney general filed a lawsuit alleging Actavis violated antitrust law by planning to prematurely end sales of the drug to force patients to switch to a newer version.

The...