WASHINGTON — Two back-to-back court developments this week indicate a possible road map for President Trump through the minefield of legal resistance he has faced as judges across the country have blocked much of his hard-line immigration agenda.

On Tuesday, a federal judge ruled in favor of an Obama-era immigration program but offered Mr. Trump the chance for a do-over, giving the president 90 days to provide a stronger legal justification to shut down the program, known as Deferred Action for Childhood Arrivals, which protects young immigrants from deportation.

On Wednesday, in a separate case involving Mr. Trump’s efforts to ban travel from several predominantly Muslim countries, the Supreme Court strongly signaled that the administration’s third try at the issue would work. Questions by the justices indicated that they would most likely back Mr. Trump’s revised effort to assert executive authority over the border with “extreme vetting.”

The judiciary has historically given presidents wide latitude to limit immigration, enforce the country’s borders and manage national security. Now, after a year and a half of deep skepticism about Mr. Trump’s immigration policies, legal experts said the courts are effectively saying that Mr. Trump can earn that kind of latitude if he goes about it the right way.