US officials have decided to allow a group of Afghan girls - whose visa applications had been rejected twice - to travel to the United States and participate in an international robotics competition, ending a saga that had sparked an international backlash.

Department of Homeland Security spokesman David Lapan said the US Citizenship and Immigration Services approved a Department of State 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 organising the competition celebrated the reversal in a statement on 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, the president of First Global.

WATCH 101 East: Afghanistan: No Country for Women

He credited "the professional leadership of the US State Department" for ensuring that all 163 teams from 157 countries, including a team of Syrian refugees, would be able to participate.

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

A senior administration official, speaking on the condition of anonymity, said that Trump raised the issue with his national security adviser, HR General 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 the idea of "paroling" the girls.

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, the girls would have had to watch via video link from their hometown in western Afghanistan.

'We want to show the world our talents'

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, according to the AP news agency. "We applied again for the US 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 recognise orange and blue colours, and can move objects to put them in their correct places.

In an interview with Al Jazeera before the turnaround, team member Rodaba Noori said: "We wanted to show our talents to the world so they would know that we do have skills."

The girls traveled from their homes in Herat, making the 800-kilometre (500-mile) journey to the US embassy in Kabul twice because their applications were denied the first time.

"Afghanistan is a country at war and doesn't have a lot of resources at hand," team member Fatima Qadari told Al Jazeera. "Other countries should consider this, they shouldn't be so strict with us."

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 Islamic State of Iraq and the Levant (ISIL, also known as ISIS) group's 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 The Gambia were also granted visas after initially being denied.