Two American hikers jailed in Iran since 2009 were freed from prison Wednesday and flown to Oman, where they were reunited with joyful family members.

Shane Bauer and Joshua Fattal, both 29, were released Wednesday evening local time after spending more than two years in prison on charges of illegal entry and espionage since they and a companion, Sarah Shourd, were arrested on the border between Iraq and Iran while hiking in the mountainous region. Shourd, who was freed last year and is engaged to Bauer, was on hand in Oman to greet the two as they ran down the stairs from the private plane that picked them up in Iran and flew them to freedom.

“We’re so happy we are free,” Fattal told reporters at Muscat International Airport in Oman.

“Two years in prison is too long,” Bauer said. He expressed hope that Wednesday’s release would lead to “freedom for political prisoners in America and Iran.” After making their brief statements, Bauer and Fattal left the airport with their families.

The release came a day before Iranian President Mahmoud Ahmadinejad was scheduled to address the U.N. General Assembly in New York, and it seemed timed at least in part as a goodwill gesture ahead of the speech.

“We are thrilled,” said President Obama, also in New York for the U.N. session, after being informed of the release. He told reporters it was a “wonderful day” for the two men’s families “and for us.”

In a statement issued later by the White House, Obama praised “the tireless advocacy” of the families. He also expressed gratitude to Oman’s Sultan Qaboos bin Said, the ruler of the tiny monarchy on the Arabian Peninsula, and to Iraqi President Jalal Talabani, the Swiss government and others around the world “who have worked steadfastly over the past two years to secure the release of Shane and Josh.”

A convoy of official cars left Tehran’s notorious Evin prison about 6:30 p.m. local time (10 a.m. in Washington), the government-controlled Islamic Republic News Agency reported.

The plane carrying the hikers left Tehran’s Mehrabad Airport and arrived in Oman about 3:40 p.m. Washington time.

The two men raced down the aircraft’s stairs to embrace family members waiting on the tarmac, television images showed.

Both men were surrounded by journalists and U.S. Embassy officials, as Bauer hugged Shourd, who was released from Evin prison in September 2010 on medical grounds.

“Today can only be described as the best day of our lives,” the family members said in a joint statement reported by the Associated Press. “We have waited for nearly 26 months for this moment,” it added. “We now all want nothing more than to wrap Shane and Josh in our arms, catch up on two lost years and make a new beginning, for them and for all of us.”

Masoud Shafiei, an Iranian lawyer representing Bauer and Fattal, spent two hours inside the prison complex earlier in the day completing paperwork for the Americans’ release. He told the semiofficial Iranian Students News Agency that the government of Oman had paid $1 million bail for Bauer and Fattal. Oman also reportedly paid bail last year to secure the release of Shourd.

After signing the papers, Shafiei waited outside the prison with the Swiss ambassador to Iran, Livia Leu Agosti, who represents U.S. interests in the country because Washington and Tehran do not have diplomatic relations.

When two Iranian government cars left the prison complex, presumably with the Americans inside, Shafiei and Agosti sped after them.

Bauer and Fattal were convicted of espionage charges in a closed trial last month. They denied being spies, maintaining that if they crossed the Iranian border, they did so accidentally while hiking with Shourd.

Ahmadinejad told journalists from The Washington Post and NBC News last week that Bauer and Fattal would receive a “unilateral pardon” and would be home “within days.”

The next day, Iran’s judiciary, which is led by Shiite Muslim clerics who once supported Ahmadinejad but now oppose him, reacted angrily, stressing that Ahmadinejad did not have the authority to free the men.

On Sunday, the men’s release was delayed again because one of the judges whose signature is required on the bail paperwork was on vacation. Shafiei said that he had received the second signature Wednesday morning.

The controversy over the hikers was the dominant backdrop as Ahmadinejad headed to New York on Monday to participate in the annual U.N. General Assembly session.

News of the release was welcomed Wednesday by officials from the Council on American-Islamic Relations, who were part of a delegation of U.S. religious leaders and American Muslims who traveled to Iran to ask that the hikers be allowed to leave.

“We believe the efforts of the recent interfaith delegation to Iran offer a positive example of bridge-building initiatives that may be undertaken to help promote mutual understanding and cooperation between nations,” CAIR National Executive Director Nihad Awad said in a statement. “We hope our government will now address the issue of Iranian citizens detained in the United States with the same spirit of compassion.”

Staff writer William Branigin in Washington contributed to this report.