MILAN—Ferrari NV’s two largest investors signed a shareholders’ pact that effectively protects the Italian sports-car maker from unwanted suitors

The agreement between Exor SpA, the Agnelli family holding company, and Piero Ferrari, son of Ferrari’s founder, will take effect in the first few days of January after the car maker is spun off next month from Fiat Chrysler Automobiles NV. The spinoff ends Fiat Chrysler’s 30 years of exclusive control of Ferrari.

Exor and Mr. Ferrari had previously disclosed their intention to sign a shareholders’ agreement though no details had been released.

As part of their agreement, Exor and Mr. Ferrari will consult ahead of Ferrari shareholders’ meetings with the aim of forming a common stance. In the event Mr. Ferrari wants to sell shares to a third party, Exor will have the right to acquire the stake at the price Mr. Ferrari might have received from a potential buyer.

Mr. Ferrari also has the right to make the first offer for any shares Exor might decide to sell. Exor would be free to accept or reject Mr. Ferrari’s offer.