WASHINGTON -- A group of girls from Afghanistan are finally getting their wish of coming to the United States for a robotics competition.

The girls' applications for U.S. visas had been denied twice, but the White House says President Donald Trump intervened and they will be allowed in to participate in the competition.

White House spokeswoman Sarah Huckabee Sanders confirmed details of the reversal Wednesday, ending a saga that had sparked international backlash.

Homeland Security Department spokesman David Lapan said the U.S. Citizenship and Immigration Services approved a State Department request for six girls from the war-torn country to be allowed in, along with their chaperone, so they can participate in the competition.

The non-profit organizing the competition celebrated the reversal in a jubilant statement Wednesday.

"I truly believe our greatest power is the power to convene nations, to bring people together in the pursuit of a common goal and prove that our similarities greatly outweigh our differences," said Joe Sestak, president of FIRST Global. He credited "the professional leadership of the U.S. State Department" for ensuring that all 163 teams from 157 countries, including a team of Syrian refugees, would be able to participate.

The U.S. State Department had declined to comment on why the Afghan team's visa applications were denied, saying that "all visa applications are adjudicated on a case-by-case basis in accordance with U.S. law."

A senior administration official said that Trump raised the issue with his national security adviser, H.R. McMaster, during his trip to Germany last week for the Group of 20 summit, and had asked for additional options. The State Department and Department of Homeland Security came up with several -- with the idea of "paroling" the girls through the Department of Homeland Security, the option ultimately chosen by the National Security Council. The person spoke on condition of anonymity to discuss the private deliberations.

Parole is a temporary status in which a person who is otherwise ineligible to enter the country is allowed in temporarily because of an emergency or humanitarian purpose, or because it's deemed to be in the public good.

Without the reversal, which was first reported by Politico, the girls would have had to watch via video link from their hometown in western Afghanistan.

The girls wanted to show the world that Afghans could also construct a hand-made robot and they had been deeply disappointed by the initial rejections.

"When we heard that we were rejected we lost hope," said 14-year-old Sumaya Farooqi. "We applied again for the U.S. visa and we were rejected again."

Farooqi and her teammates faced seemingly insurmountable obstacles to even get to a point where they could seek permission to attend. It took them six months to prepare, often working seven days a week, as they constructed a robot that sorts balls, has the ability to recognize orange and blue colours, and can move objects to put them in their correct places.

The girls travelled from their homes in Herat after convincing family members to let them go -- no small feat in a country where young girls are often discouraged from pursuing academic study, especially in hard sciences such as math.

They made the 800-kilometre (500-mile) journey to the U.S. Embassy in Kabul twice because their applications were denied the first time, even though that location was targeted by a deadly truck bomb on May 31 in which more than 150 people were killed and more than 400 others wounded.

War-torn Afghanistan has faced a series of large-scale attacks as the Taliban stepped up its war against the Kabul government in this year's summer offensive. In addition, the emerging Islamic State group affiliate in Afghanistan has tried to increase its footprint with attacks in urban areas.

Afghanistan is not part of Trump's order to temporarily ban travel from six Muslim-majority countries. Teams from Syria, Iran and Sudan -- which are on that list -- were granted visas to compete. Members of the team from Gambia were also granted visas after initially being denied.

First Global, a not-for-profit charity, holds the annual international robotics challenge in hopes of sparking a passion for science and technology among high school students around the world. It is an "Olympics"-style competition in which one team from every nation is invited to participate. It takes place July 16-18 in Washington, D.C.

----

Associated Press writer Josh Lederman contributed to this report.