Al-Qaeda in the Arabian Peninsula (AQAP) was formed in January 2009 by a merger between two regional offshoots of the international jihadist network in Yemen and Saudi Arabia.
Since then, it has become what US officials have described as "the most active operational franchise" of al-Qaeda beyond Pakistan and Afghanistan.
The group has vowed to target oil facilities, foreigners and security forces as it seeks to topple the Saudi and Yemeni governments, and establish an Islamic caliphate.
It has claimed responsibility for a large number of attacks in the two countries, in which hundreds of people have been killed, as well as a series of sophisticated airline bomb plots targeting the US that were narrowly foiled.
AQAP has also capitalised on the instability in Yemen in recent years to establish strongholds in the country's south and east, sometimes taking control of entire towns and villages.
But the group has also suffered setbacks, mostly as a result of a US drone campaign that has seen more than 100 air strikes targeting its operatives in the past six years.
In June 2015, AQAP announced that its leader Nasser al-Wuhayshi - who was believed to also have been al-Qaeda's overall second-in-command - had been killed in an air raid.
While the group was quick to replace Wuhayshi with the experienced military and operations chief, Qasim al-Raymi, analysts said his death was a significant blow.
Following the 11 September 2001 attacks in the US, the late al-Qaeda leader Osama Bin Laden sought to launch a campaign in his homeland of Saudi Arabia with the intention of driving Americans out of the country and toppling the "apostate" monarchy.
In May 2003, a local offshoot claimed responsibility for simultaneous suicide bombing attacks on three Western housing compounds in Riyadh, which left 29 people dead.
Despite a subsequent crackdown on Islamist militants and radicals by the Saudi security forces, al-Qaeda in Saudi Arabia was able to mount an attack on the Muhayyah residential compound in the capital that November, killing 17 people.
In 2004, it suffered a major blow when its leader, Khaled Ali Hajj - a Yemeni and former bodyguard of Bin Laden - was ambushed and killed by Saudi troops.
However, the group soon recovered under the guidance of a veteran Saudi militant, Abdul Aziz al-Muqrin, and launched a series of spectacular attacks.
On 1 May 2004, militants shot dead five Western workers at a petrochemical complex in the north-western Red Sea city of Yanbu. On 29 May, more than 20 foreign and Saudi nationals were killed in attacks on three sites in the city of al-Khobar, increasing fears of political instability and pushing up global oil prices.
The following month, members of AQAP abducted and beheaded a 49-year old American aerospace worker named Paul Johnson.
The triumph was short-lived, however, as when security forces stormed a hideout in Riyadh looking for Johnson's murderers Muqrin was shot dead.
Although militants killed at least nine people in a raid on the US consulate in Jeddah in December 2004, al-Qaeda in the Arabian Peninsula enjoyed notably less success under Muqrin's successor, Salih al-Awfi.
The Saudi security services gradually gained the upper hand, and succeed in preventing any major attacks the following year, when Awfi was himself killed during a police raid in the holy city of Medina.
In spite of the large numbers of Saudis who then travelled to militant training camps and gained experience fighting in places such as Iraq, the group found it increasingly difficult to organise operational cells inside the kingdom. Its last attempt a significant attack was at the Abqaiq oil facility in February 2006.
Meanwhile in Yemen - the ancestral home of Bin Laden - militants took advantage of the weak central government, whose authority does not extend far outside the capital Sanaa, and established strongholds in its largely autonomous tribal regions.
Although al-Qaeda cells were held responsible for several attacks inside Yemen since the suicide boat attack on the USS Cole near the port of Aden in 2000 that killed 17 US sailors, it was not until the second half of the decade that a fully-functioning affiliated group was formed.
According to analyst Gregory Johnsen, between 2002 and 2003 the Yemeni government co-operated closely with the US to fight al-Qaeda. By the end of that period - which included one leader being killed in a controversial strike by a CIA drone aircraft - al-Qaeda appeared to be substantially weakened and so both countries shifted focus.
The policy appeared to have worked until February 2006, Mr Johnsen says, when 23 suspected al-Qaeda members managed to escape from a prison in Sanaa, including Jamal al-Badawi, the alleged mastermind of the USS Cole bombing.
Most were eventually either recaptured or killed, but two of the lesser-known escapees eluded the authorities, including Nasser Abdul Karim al-Wuhayshi, a former personal assistant to Bin Laden in Afghanistan, and Qasim al-Raymi.
Born in 1976 in the Mukayras region of what is now the southern province of al-Bayda, Wuhayshi spent time in religious institutions in Yemen before travelling to Afghanistan in 1998 and joining al-Qaeda. He fought at the battle of Tora Bora in December 2001, before escaping over the border into Iran, where he was eventually arrested. He was extradited to Yemen in 2003.
Raymi, born in Sanaa in 1978, was as a trainer at an al-Qaeda camp in Afghanistan in the 1990s before returning to Yemen. In 2004, he was imprisoned for five years in connection with a plot to attack five foreign embassies in the capital.
After escaping from prison, Wuhayshi and Raymi are said to have overseen the formation of al-Qaeda in Yemen, which took in both new recruits and experienced Arab fighters returning from Iraq and Afghanistan. Protected by tribes who were wary of government interference, the group established bases from which to launch fresh attacks.
The group claimed responsibility for two suicide bomb attacks that killed six Western tourists before being linked to the assault on the US embassy in Sanaa in September 2008, in which militants detonated bombs and fired rocket-propelled grenades. Ten Yemeni guards and four civilians were killed, along with six assailants.
Four months later, Wuhayshi announced in a video the merger of the al-Qaeda offshoots in Yemen and Saudi Arabia to form "al-Qaeda of Jihad Organisation in the Arabian Peninsula".
Analysts said the move was designed to bring Saudi al-Qaeda members who had fled their country and Yemeni militants together under one umbrella as a first step towards launching attacks throughout the region.
Next to Wuhayshi and Raymi, the group's military commander, in the same video sat the new deputy leader, Said Ali al-Shihri, a Saudi national who was released from the US military detention centre at Guantanamo Bay in November 2007.
Another former detainee, Mohammed Atiq al-Harbi, also known as Mohammed al-Awfi, appeared alongside them and was described as a field commander.
Embarrassingly for both Riyadh and Washington, both men had been released from Guantanamo into the custody of the Saudi government's "deradicalisation" programme for militants, which included art therapy. They both left the facility within weeks.
The group's first operation outside Yemen was carried out in Saudi Arabia in August 2009 against the kingdom's security chief, Prince Mohammed bin Nayef, though he survived. The bomber, Ahmed al-Asiri, concealed a device containing the high-explosive pentaerythritol tetranitrate (PETN) inside his body.
His brother, Ibrahim, is believed to have made the bomb, as well as the device used in the failed attempt to destroy a Northwest Airlines Airbus A330 as it flew into Detroit on Christmas Day 2011.
After news of the latter incident emerged, AQAP released a statement saying it had sought to avenge raids by Yemeni forces aided by US intelligence, in which dozens of militants are reported to have died.
Following the bombing attempt, Yemeni government forces launched a major offensive against AQAP, targeting the organisation's senior leaders and training camps in the governorates of Shabwa, Abyan and Marib.
They were supported heavily by the US, which sent advisers, provided intelligence, deployed unmanned drones and fired cruise missiles.
Though officials claimed six leaders were killed, the offensive was considered largely unsuccessful. Instead of decapitating AQAP and disrupting its operations, the group shifted its strategy and stepped up its attacks inside Yemen.
In February 2010, Raymi issued a statement threatening the US.
"Today, you have attacked us in the middle of our household, so wait for what will befall you in the middle of yours," he said. "We will blow up the earth from beneath your feet".
Eight months later, the group was accused of sending bombs hidden in two packages addressed to synagogues in the US city of Chicago, which were found on planes in Dubai and the UK.
Both were shipped from Yemen and used PETN, the explosive that was also used in the two earlier attacks on Prince Mohammed and the Northwest Airlines jet. One of the detonators was also almost exactly the same as the one used by Mr Abdulmutallab. US officials said Ibrahim al-Asiri had made them.
At home, AQAP capitalised on political turmoil in Yemen resulting from the uprising against longtime President Ali Abdullah Saleh in 2011 to capture a string of southern towns and villages, only to be driven out of many areas in an army offensive in 2012 ordered by Mr Saleh's successor, Abdrabbuh Mansour Hadi.
At the same time, US President Barack Obama authorised a three-fold increase in the number of drone strikes targeting AQAP operatives in Yemen in 2012, resulting in the deaths of a number of senior figures, including Shihri, the deputy leader.
The territorial losses did not, however, stop AQAP from launching major attacks Yemeni security forces and government personnel.
In March 2014, Wuhayshi was filmed telling a outdoor gathering of dozens of militants that al-Qaeda would fight Western "Crusaders" and their allies everywhere, pledging to "remove the cross, the bearer of the cross, America".
That December, the group threatened to kill an American journalist it was holding hostage, Luke Somers, if its unspecified demands were not met within three days. As the deadline approached, Somers was killed along with another hostage, South African teacher Pierre Korkie, during a failed rescue attempt by US special forces.
AQAP also refused to pledge allegiance to the leader of the rival jihadist group, Islamic State, after it proclaimed the creation of caliphate in the territory under its control in Syria and Iraq, bucking the trend among other al-Qaeda affiliates.
In Yemen, AQAP capitalised on the chaos caused by a rebellion by the Houthi movement and a Saudi-led air campaign to weaken the Zaidi Shia group, expanding the territory it controlled in the south and east of the country.
However, the US drone strikes targeting AQAP did not stop and one was reported to have killed Wuhayshi as he met two fellow militants in Mukalla on 9 June.
On 16 June, AQAP official Khaled Batarfi confirmed Wuhayshi's death in a video statement and vowed that "the blood of these pioneers makes us more determined to sacrifice". Batarfi also said Raymi had been elected by the group's leadership council to succeed Wuhayshi.