WASHINGTON — The Pentagon approved a gender-reassignment surgery for an active-duty military member, defense officials said on Tuesday, four months after President Trump abruptly announced a ban on transgender people serving in the military.

The surgery is the latest setback to Mr. Trump’s effort to put a ban in place. Two weeks ago, a federal judge temporarily blocked the ban, ruling that the justification for it was suspect and most likely unconstitutional.

Even before the ruling, officials at the Defense Department had been slow-walking Mr. Trump’s orders, telling transgender members of the military that they could continue to serve openly while the Pentagon decided how to handle the ban.