Qatar has restored full diplomatic relations with Iran, defying the demands of Arab nations now trying to isolate the energy-rich country to downgrade its ties.
Qatar's Foreign Ministry announced early on Thursday that the country's ambassador would return to Tehran.
The country withdrew its ambassador in early 2016 after Saudi Arabia's execution of a prominent Shiite cleric sparked attacks on two Saudi diplomatic posts in Iran.
Qatar said in a statement that the move "expressed its aspiration to strengthen bilateral relations with the Islamic Republic of Iran in all fields".
Iranian state media acknowledged the development, without elaborating.
Qatar and Iran share a massive offshore natural gas field that requires communication between the two countries.
Since the diplomatic dispute with Arab nations began in June, Iran has sent food shipments to Qatar.
In announcing its decision, Qatar did not mention the diplomatic crisis among Gulf Arab nations since June, when Qatar found its land, sea and air routes cut off by its neighbours over Doha's policies across the Middle East.
However, the move comes just days after Saudi Arabia began promoting a Qatari royal family member whose branch of the family was ousted in a palace coup in 1972.
"Qatar has shown it is going to go in a different direction," said Kristian Coates Ulrichsen, a research fellow at the James A Baker Institute for Public Policy at Rice University.
"It could very well be calculated toward reinforcing the point that Qatar will not bow to this regional pressure placed upon it."
The shared gas field's vast reserves made Qataris have the highest per capita income in the world, as well as funded the nation's Al-Jazeera satellite news network and secured hosting the 2022 Fifa World Cup.
Shiite power Iran has incorporated the crisis into its regular criticism of the Sunni-ruled Saudi Arabia, part of the two powers' long-running proxy war.
On Wednesday, the Central African nation of Chad announced it would close its embassy in Doha, accusing Qatar of trying to destabilise it from neighbouring Libya.
The diplomatic crisis began on June 5, when Bahrain, Egypt, Saudi Arabia and the United Arab Emirates cut ties to Qatar over allegations including it funding extremists and being too close to Iran.
Qatar has long denied supporting extremists.
The boycotting countries later issued a list of 13 demands to Qatar, including that Doha shut its diplomatic posts in Iran.
Qatar ignored the demands and let a deadline to comply pass, creating an apparent stalemate in the crisis. Attempts by Kuwait, the US and others have failed to make headway.
In recent days, however, Saudi Arabia announced it would allow Qataris to make the annual hajj pilgrimage, which is required of all able-bodied Muslims once in their life.
Saudi state media said that came in part due to an intercession by Qatari royal family member Sheikh Abdullah Al Thani, who met Saudi Crown Prince Mohammed bin Salman and later a holidaying King Salman in Morocco.
But Sheikh Abdullah has no role in Qatar's government and his last position was as head of the equestrian and camel racing federation decades ago.
Sheikh Abdullah's grandfather, father and brother were rulers of Qatar until a palace coup ousted his branch of the royal family in 1972 and a prominent Saudi columnist has suggested the sheikh could be the start of a Qatari government-in-exile.