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 Judge Timothy Kelly, who was appointed to the bench by President Trump, granted CNN’s request for a restraining order, temporarily restoring Mr. Acosta’s press access to the White House while the case proceeds.

In seeking such motions, plaintiffs typically must show that they are likely to win the case on the merits. So while Friday’s ruling doesn’t resolve the underlying dispute, it suggests CNN would ultimately prevail.

Speaking from the bench, Judge Kelly said that Mr. Acosta’s constitutional rights to due process appear to have been violated by the White House, justifying a tentative restoration of the press credential while Judge Kelly hears further arguments from both sides.