ISTANBUL — More than eight decades ago, Ertugrul Osman, an heir to the Ottoman throne, was unceremoniously thrown out of Turkey with his family. He lived to be 97, spending most of his years in a modest Manhattan apartment above a bakery.

But in September, at his funeral in the garden of the majestic Sultanahmet Mosque here, thousands of mourners came to pay their respects, including government officials and celebrities. Some even kissed the hands of surviving dynasty members, who appeared shocked at the adulation.

The show of reverence for the man who might have been sultan, historians said, was a seminal moment in the rehabilitation of the Ottoman Empire, long demonized by some in the modern, secular Turkish Republic created by Mustafa Kemal Ataturk in 1923. During Ataturk’s rule, the empire was remembered mainly for its decadence and its humiliating defeat and partition by the Allied armies in World War I.

Mr. Osman’s send-off was just the latest manifestation of what sociologists call “Ottomania,” a harking back to an era marked by conquest and cultural splendor during which sultans ruled an empire stretching from the Balkans to the Indian Ocean and claimed the spiritual leadership of the Muslim world.

The longing for those glory years — by religious Muslims and secularists alike — partly reflects Turks’ frustration with a European Union that seems ill disposed to accept them as members. And in a country where the tension between religion and secularism is never far from the surface, members of the new governing class of religious Muslims have seized upon nostalgia for the Ottoman Empire as a way to challenge the pro-Western elite that emerged during Ataturk’s rule, and to help forge a national identity of Turkey as an aspiring regional leader.

“Turks are attracted to the heroism and the glory of the Ottoman period because it belongs to them,” said the director of Topkapi Palace, Ilber Ortayli, who, as the keeper of the sumptuous residence where Ottoman sultans lived for 400 years, is also a zealous unofficial gatekeeper of the country’s Ottoman legacy. “The sultans hold a place in the popular consciousness like Douglas MacArthur or General Patton have for Americans.”

The current vogue of all things Ottoman, from the proliferation of historical docudramas to the popularity of porcelain ashtrays adorned with half-naked harem women, is sometimes manifesting itself in ways that would surely have made a real sultan blanch.

During Ramadan, Burger King offered a special sultan menu featuring dishes popular in the Ottoman years. In the television commercial promoting the meal, a turbaned Janissary — a member of an elite group of Ottoman soldiers known for their warrior spirit — exhorts viewers not to “leave any burgers standing.”

Ottomania has also infected the nation’s youth; 20-somethings at hip dance clubs here wear T-shirts emblazoned with slogans like “The Empire Strikes Back” or “Terrible Turks” — the latter turning the taunt Europeans once used against their Ottoman invaders into a defiant symbol of self-affirmation.

Kerim Sarc, 42, the owner of Ottoman Empire T-Shirts and the scion of an illustrious Ottoman family, believes that the newfound fondness for a mighty empire that lasted 600 years and once reached the gates of Vienna is linked to the long struggle for membership in the European Union. The bloc has imposed tough conditions on Turkey, including asking it to compromise in its longstanding dispute over Cyprus.

“We Turks are tired of being treated in Europe like poor, backward peasants,” he said.

The Ottoman renaissance is equally prevalent in the nation’s highest political circles, where the Muslim-inspired Justice and Development Party government has been aggressively courting former Ottoman colonies, including Iraq and Syria, in at least a partial reorientation of foreign policy toward the east that Turkish analysts have labeled as “Neo-Ottoman.”

That shift has alarmed officials in Europe and Washington, and Prime Minister Recep Tayyip Erdogan is expected to reassure President Obama when he meets him at the White House on Monday that Turkey has not abandoned its Western course.

It is a sign of the Ottoman Empire’s new hold on the popular imagination that in January when Mr. Erdogan publicly rebuked the Israeli president, Shimon Peres, over the war in Gaza, at a debate at Davos, Switzerland, he was greeted enthusiastically by his supporters back in Turkey with the chant, “Our fatih is back!” The allusion was to Fatih — or conqueror — Sultan Mehmet II, the towering sultan who at age 21 conquered Constantinople, now Istanbul, in 1453.

Colleagues said Mr. Erdogan proudly displays an original decree in his office by Sultan Mehmet II granting autonomy to religious minorities within the empire.

“The Ottoman Empire conquered two-thirds of the world but did not force anyone to change their language or religion at a time when minorities elsewhere were being oppressed,” said Egeman Bagis, the minister for European Union affairs. “Turks can be proud of that legacy.”

Pelin Batu, co-host of a popular television history program, argued that the glorification of the Ottoman era by a government with roots in political Islam reflected a revolt against the secular cultural revolution undertaken by Ataturk, who outlawed the wearing of Islamic head scarves in state institutions and abolished the Ottoman-era caliphate, the spiritual head of Sunni Islam.

“Ottomania is a form of Islamic empowerment for a new Muslim religious bourgeoisie who are reacting against Ataturk’s attempt to relegate religion and Islam to the sidelines,” she said.

In a society struggling with its identity, not everyone welcomes the phenomenon.

Some critics accuse its proponents of glossing over the empire’s decline and of glorifying an anachronistic system that, at the very least, was mired in corruption and infighting in its later years. The massacre of Ottoman Armenians between 1915 and 1918 stands as a particular dark spot in the history of the empire.

“The religious Muslims now in power are trying to feed the Turkish people an Ottoman poison,” said Sada Kural, 45, a housewife and staunch supporter of Ataturk’s vision for the country. “The Ottoman era wasn’t a good period; we were the sick man of Europe, rights were suppressed and women only got the vote after Ataturk came to power.”

While some bemoan what they consider the crude commercialization of a nation’s history, others, like Cenan Sarc, 97, who was 10 years old at the time of the empire’s collapse in 1922 and is the descendant of an Ottoman pasha, cautioned against idealizing an era of dictatorship.

Mrs. Sarc recalled her idyllic childhood in an old Ottoman mansion on the Bosporus, a poetic time, she said, when fathers ruled, mothers stayed at home and Islam held sway. But, she insisted, “we can never go back to that time.” Ertugrul Osman, the Ottoman heir who was the grandson of Sultan Abdul Hamid II, had himself accepted obscurity. When he visited Turkey in 1992, for the first time in 53 years, and went to see the 285-room Dolmabahce Palace, which had been his grandfather’s home, he insisted on joining a public tour group.

Asked frequently if he dreamed about restoring the empire, he always emphatically answered no. “Democracy,” he said, “works well in Turkey.”