Ports of Auckland has been prohibited from contracting out wharfies' work until at least 16 May.
The injunction, sought by the Council of Trade Unions and the Maritime Union, was granted at an Employment Court hearing on Tuesday.
The hearing is also determining whether the ports company can legally lock out staff, while contract negotiations continue.
CTU president Helen Kelly says the judge's decision to stop the ports company's plans to contract out work is a good outcome.
She says the injunction vindicates the Maritime Union's position.
The hearing will resume on Friday, where the legality of the lock out will be discussed.
Last week, the council-owned port company agreed to resume negotiations with the Maritime Union after an Employment Court judge encouraged both parties to return to mediation.
The following day it issued a lock out notice to the union workers and would not allow them back to work in the interim.