Military officers carry the coffin of late president Beji Caid Essebsi during his state funeral at the presidential palace in the capital's eastern suburb of Carthage, Saturday July 27, 2019.  Many Tunisian and visiting international dignitaries have gathered for the funeral of Essebsi, the country's first elected head of state who died aged 92. (Fethi Belaid / Pool via AP)

TUNIS, Tunisia (AP) — Tunisians and world leaders bid adieu on Saturday to the country's first democratically elected president, Beji Caid Essebsi, who died in office at 92 and left the North African nation facing new political uncertainty.

Thousands of people lined the route of the funeral cortege, crying "Long Live Tunisia!" and waving red-and-white Tunisian flags. Some wept openly.

The king of Spain, president of France and emir of Qatar were among several world leaders attending the ceremony in Tunis at the presidential palace.

Exceptional security measures were in place after threats linked to the Islamic State extremist group. The 20-kilometer (12-mile) cortege route was closed to all traffic, from the palace to the Jellaz cemetery on the other side of the city.

Essebsi won Tunisia's first free election after the 2011 uprising that brought democracy to the country and unleashed uprisings around the Arab world.

Upon his death, parliament chief Mohamed Ennaceur took over as interim president pending a new election on Sept. 15.

A tearful Ennaceur praised Essebsi for "defending the values of liberty, the law and the prestige of the state, and making dialogue, consensus and peaceful transitions prevail."

"You will remain at our sides as a symbol and a model," Ennaceur added, promising to pursue a democratic path.

The centrist Essebsi was seen as a unifying figure after the upheaval of the 2011 uprising, though he didn't manage to pull Tunisia out of economic troubles or stem sporadic extremist attacks.

International speakers described his death as a loss for the Arab-Muslim world and the Mediterranean region.

Tunisia is the only country to emerge from the Arab Spring with a functioning democracy and is relatively open and stable compared to other countries in the region.

French President Emmanuel Macron said he had lost "a friend" with Essebsi's death. Essebsi was a symbol of the generation that shook off French rule in the 1950s, but Tunisia retains close economic and cultural ties with France.

People react as the convoy carrying the body of Tunisian President Beji Caid Essebsi arrives at the presidential palace in Carthage, near Tunis, Tunisia, Friday, July 26, 2019. Tunisia is inviting world leaders to attend the funeral for its president who died in office and preparing a new election to replace him. The next election was originally set for Nov. 17, but is being rescheduled after President Beji Caid Essebsi died in office Thursday at 92. (AP Photo/Hassene Dridi)
A military band  performs during the state funeral of late president Beji Caid Essebsi at the presidential palace in the capital's eastern suburb of Carthage, Saturday July 27, 2019.  Many Tunisian and visiting international dignitaries have gathered for the funeral of Essebsi, the country's first elected head of state who died aged 92. (Fethi Belaid / Pool via AP)
Guests from left,  Spanish King Felipe VI, The emir of Qatar Sheikh Tamim bin Hamad al-Thani, French President Emmanuel Macron and Libya's Prime Minister Fayez al-Sarraj, attend the state funeral of late president Beji Caid Essebsi at the presidential palace in the capital's eastern suburb of Carthage, Saturday July 27, 2019.  Many Tunisian and visiting international dignitaries have gathered for the funeral of Essebsi, the country's first elected head of state who died aged 92. (Fethi Belaid / Pool via AP)
People react as the convoy carrying the body of Tunisian President Beji Caid Essebsi arrives at the presidential palace in Carthage, near Tunis, Tunisia, Friday, July 26, 2019. Tunisia is inviting world leaders to attend the funeral for its president who died in office and preparing a new election to replace him. The next election was originally set for Nov. 17, but is being rescheduled after President Beji Caid Essebsi died in office Thursday at 92. (AP Photo/Hassene Dridi)
French President Emmanuel Macron speaks during the state funeral of late president Beji Caid Essebsi at the presidential palace in the capital's eastern suburb of Carthage, Saturday July 27, 2019.  Many Tunisian and visiting international dignitaries have gathered for the funeral of Essebsi, the country's first elected head of state who died aged 92. (Fethi Belaid / Pool via AP)
Spanish King Felipe VI speaks during the state funeral of late president Beji Caid Essebsi at the presidential palace in the capital's eastern suburb of Carthage, Saturday July 27, 2019.  Many Tunisian and visiting international dignitaries have gathered for the funeral of Essebsi, the country's first elected head of state who died aged 92. (Fethi Belaid / Pool via AP)
Palestinian President Mahmoud Abbas speaks during the state funeral of late president Beji Caid Essebsi at the presidential palace in the capital's eastern suburb of Carthage, Saturday July 27, 2019.  Many Tunisian and visiting international dignitaries have gathered for the funeral of Essebsi, the country's first elected head of state who died aged 92. (Fethi Belaid / Pool via AP)
French President Emmanuel Macron greets the emir of Qatar Sheikh Tamim bin Hamad al-Thani, centre, next to Spanish King Felipe VI, right, during the state funeral of late president Beji Caid Essebsi at the presidential palace in the capital's eastern suburb of Carthage, Saturday July 27, 2019.  Many Tunisian and visiting international dignitaries have gathered for the funeral of Essebsi, the country's first elected head of state who died aged 92. (Fethi Belaid / Pool via AP)