WASHINGTON—A federal judge granted an emergency motion Friday to restore the White House press credential of CNN correspondent Jim Acosta, a victory for the network in a closely watched press-freedom case.

The lawsuit, which drew the attention of major media outlets and press-freedom advocates, could establish a new precedent on when the government can ban individual reporters from public buildings.

District...