Bloomberg via Getty Images U.S. President Donald Trump listens during a news conference with Sheikh Sabah Al-Ahmed Al-Sabah, Kuwait's emir, not pictured, in the East Room of the White House in Washington, D.C., U.S., on Thursday, Sept. 7, 2017. (Andrew Harrer/Bloomberg via Getty Images)

By Mica Rosenberg and Jonathan Stempel

NEW YORK (Reuters) - A U.S. appeals court on Thursday rejected the Trump administration’s effort to temporarily bar most refugees from entering the country, ruling that those who have relationships with a resettlement agency should be exempt from an executive order banning refugees.

A three-judge 9th U.S. Circuit Court of Appeals panel also ruled that grandparents, aunts, uncles and cousins of legal U.S. residents should be exempted from President Donald Trump’s order, which banned travelers from six Muslim-majority countries.

The ruling is the latest legal blow to the President’s sweeping executive order barring travelers from Iran, Syria, Libya, Somalia, Sudan and Yemen for 90 days, which the Republican president said was necessary for national security.

The Justices said that the government did not persuasively explain why the travel ban should be enforced against close relatives of people from the six countries or refugees with guarantees from resettlement agencies. The 3-0 ruling takes effect in five days.

The U.S. Supreme Court ruled in June that Trump’s ban could be implemented on a limited basis, but should not be applied to people with “bona fide” relationships to people or entities in the United States.

The government took a narrow view of that interpretation, which the state of Hawaii challenged in court. A lower court judge sided with Hawaii, and the 9th Circuit judges upheld that view.

“It is hard to see how a grandparent, grandchild, aunt, uncle, niece, nephew, sibling-in-law, or cousin can be considered to have no bona fide relationship with their relative in the United States,” the court said.

The court also rejected the administration’s argument that the written assurances provided by resettlement agencies obligating them to provide services for specific refugees is not a bona fide relationship.

The agencies’ advance preparation and expenditure of resources for each refugee “supports the district court’s determination that a bona fide relationship with the refugee exists,” the decision said.

Trump’s first version of the executive order, signed in January, sparked protests and chaos at airports around the country and the world before it was blocked by courts. The administration replaced that version of the ban with a new order in March in response to the legal challenges.

A Department of Justice spokeswoman said: “The Supreme Court has stepped in to correct these lower courts before, and we will now return to the Supreme Court to vindicate the Executive Branch’s duty to protect the Nation.”

Hawaii’s Attorney General Douglas Chin said the ruling “keeps families together. It gives vetted refugees a second chance. The Trump administration keeps taking actions with no legal basis. We will keep fighting back.”

Refugee organizations cheered Thursday’s decision, saying it will give relief to people fleeing violence who were caught in limbo after the ban.

The broader question of whether the revised travel ban discriminates against Muslims in violation of the U.S. Constitution will be considered by the U.S. Supreme Court in October.

(Reporting by Mica Rosenberg and Jonathan Stempel in New York; Additional reporting by Andrew Chung and Lawrence Hurley in Washington; editing by Sue Horton and Grant McCool)