Red Village rises up along the Qudiyal River like a Jewish Brigadoon.

To get there, you fly 13 hours from Los Angeles to Istanbul, then catch a three-hour flight to Baku, the capital of Azerbaijan — a former Soviet country of some 9 million people on the Caspian Sea. From Baku, you take a bus past churning oil derricks and miles of empty desert, up into the Caucasus, through tiny villages surrounded by apple orchards. After two hours, you arrive in Quba, the capital of Azerbaijan’s northeast region. About a mile past an attractive central mosque, a simple steel bridge spans a wide, mostly dry riverbed and leads directly into Red Village.

One of the first things you see is a large brick building atop which sits — improbably, impossibly — a Jewish star.

About 4,000 people live in Red Village, every one of them Jewish. That makes Red Village the largest all-Jewish settlement outside the State of Israel.

[Related: The food of Azerbaijan]

This entirely Jewish town exists in an almost entirely Muslim country — ancient, placid, prosperous. It is also completely unknown to the majority of the world’s Jews. I had to see Red Village to believe it. I had to figure out: What’s the deal with Azerbaijan?

Earlier this month, Azerbaijan’s President Ilham Aliyev convened 750 journalists, scholars, activists and scientists from around the world to participate in the annual Baku International Humanitarian Forum.

The invitation offered a chance to see for myself a country that, from what I’d heard over the years, has never quite fit the standard American perception of Muslim = Fanatic and Shiite = Really Fanatic.

After all, Iran, also a Shiite nation, lies just across Azerbaijan’s southern border. But while Iran is the Jewish state’s mortal enemy, Azerbaijan is Israel’s largest supplier of oil and a major purchaser of Israeli defense technology. The Shiites of Iran would treat me, an American Jew with a passport full of Israeli stamps, as an enemy. In Azerbaijan, I was an honored guest.

My visit was personally arranged through Azerbaijan’s Western Region Consul General, Nasimi Aghayev. I’m not the first journalist lured to explore Azerbaijan’s incongruities, but I do seem to be the first in my crowd. Few people I talked to about my travel plans beforehand had heard of Azerbaijan, and even fewer of its Jewish connection.

You could fault Azeris for not getting the word out, but in the 22 years since it gained its independence, Azerbaijan has had to focus on rebuilding, not rebranding.

What struck me first when I arrived in Baku is that Azerbaijan is in the midst of a fast transition. Now that its tremendous oil and gas wealth isn’t being siphoned off to feed the Soviet empire, the country’s GDP (gross domestic product) has soared.

This group of kippot-wearing Azeri boys greeted an American visitor with laughter and shouts of “hello” and “Shabbat shalom!” Photo by Rob Eshman

For most of the 19th and early 20th centuries, Azerbaijan was under the rule of the Russian empire, which exploited its resources. When the tsar fell in 1918, Azerbaijan quickly formed a secular republic, the first Muslim majority country in the world to do so. Its parliament immediately granted women the right to vote — a year before the United States did. But the flowering of democracy, commerce and art was brief. The Bolsheviks arrived just 22 months after Azerbaijan declared independence, attacked what they called liberal and decadent Baku Muslims, crushing a rebellion and absorbing Azerbaijan into the USSR.

When Hitler invaded Russia, his brass ring was Baku’s oil, which provided more than 80 percent of the fuel for the Soviet war effort. In 1942, Hitler’s general staff gave him a cake in the shape of the Caucasus. Hitler ate the slice with “Baku” written on it. “Unless we get Baku oil,” Hitler said, “the war is lost.”

With the collapse of the Soviet Union, Baku finally won its independence in 1991. Its first president, Heydar Aliyev, who died in 2003, and his son and successor, Ilham Aliyev, have managed to negotiate lucrative long-term oil and gas contracts that, for the first time, keep Azerbaijan’s money at home and have tilted the former Soviet satellite westward.

Oil money has enabled a modern, busy city with cutting-edge architecture and luxury stores to grow up around the well-preserved walls and narrow cobblestone streets of the Old City. Baku is a cleaner Tel Aviv surrounding a smaller-walled Jerusalem.

What’s even more surprising about Baku is its people. The majority are traditional but secular. Few women wear headscarves — the look is skirts and heels, more Westwood Boulevard than Riyadh.

But Azerbaijan’s tolerance is not a Western import. It’s homegrown, even ancient.

“The multinational, multiconfessional society is one of our assets,” President Aliyev said in the conference’s keynote address. “All nationalities see their religion respected. … This contributes to the building of a civil society.”

For the Jews, that is remarkably true.

“There has never been anti-Semitism in Azerbaijan,” Arye Gut, the Azeri-born founder of the international association Israel-Azerbaijan (AZIZ), told me. Like many Azeris who have immigrated to Israel, he maintains strong personal and business ties to his home country.

In a meeting at his office, Ambassador Elshad Iskandarov, chairman of the State Committee for Work With Religious Organizations, pointed out with some understatement that Azerbaijan has resisted the increasing anti-Semitism in the Muslim world.

Iskandarov, an urbane graduate of Columbia University, theorized that Azerbaijan’s location on the Silk Road international trade route long ago encouraged its people to accept all kinds of cultures.

Or, as a Cambridge-educated Azeri told me later in my week there, “Our philosophy is, ‘Why fight when you can trade?’ ”

A masterpiece of architecture by the Iraqi-born Zaha Hadid recently opened as the Heydar Aliyev Center, a cultural and conference center in Baku. Photo by Rob Eshman

Like many Azeri officials I met, Iskandarov could rattle off the names of famous Azerbaijani Jews — who are pretty much the most famous Azerbaijanis, period — among them pianist Bella Davidovich, Nobel Prize physicist Lev Landau, Israeli singers Sarit Hadad and Yaffa Yarkoni, pioneering physician Gavril Ilizarov and chess master Garry Kasparov, who is half Armenian.

There is also writer Lev Nussimbaum, aka Essad Bey and Kurban Said, author of the most famous Azeri novel, “Ali and Nino.”

“The magic of this town lies in the mystical bond between its races and its people,” the book’s narrator said. “The race of a peaceful Caucasus is forged on the anvil of Baku.”

Iskandarov wondered aloud whether the nation didn’t share a lineage with the eighth-century Khazars who converted en masse to Judaism. Perhaps, the ambassador posited, Azerbaijani Shiites have Jewish blood.

“When we are talking about Jews,” he said, “this is tolerance of our own past.”

I asked how the government keeps extremist Islamic ideologies from taking root in Azerbaijan. Iskandarov pointed to his bookshelf, where there were thick tomes of sermons prepared by government-appointed imams and distributed to mosques — local imams were encouraged not to veer from these more liberal teachings. There is freedom of religion — but not too much.

Many countries, including Iran, say they love the Jews — it’s just Israel they can’t stand. Azerbaijan is different. It has strategic defense partnerships with Israel, and the two countries conduct $5.5 billion in trade annually.

Last year, Iran protested and even threatened “consequences” after the Azerbaijan foreign minister announced an official visit to Israel. President Aliyev refused to back down.

“I know who my friends are,” Aliyev said, “and who my enemies are.”

During the tsarist regime, Jews were not permitted to buy land in Baku. But a local Muslim stepped up and bought the property for what became one of the city’s two synagogues. On Friday night, as Sabbath services concluded, I went there to meet Milikh Yevdayev, chairman of the Religious Community of Mountain Jews.

About 10,000 of Azerbaijan’s 15,000 Jews live in Baku. The synagogues serve different groups — one is Ashkenazi style, staffed by a Chabad rabbi, and the other, the one I visited, is well-appointed and known as the New Synagogue, for the Mountain Jews.

The Mountain Jews trace their lineage to ancient Persia. They speak Juhuri, a blend of Farsi and Hebrew; if you close your eyes, you’re back again on Westwood Boulevard. Historians believe the Mountain Jews first settled in the Caucasus in the fifth century. It is their descendants who settled Red Village.

“We live like brothers,” Yevdayev assured me.

On the wall of the synagogue are photos of the stout, middle-aged Yevdayev and other synagogue leaders alongside President Aliyev, as well as the country’s leading imam and the head of the Armenian church.

The $2 million it took to build the synagogue last year came directly from President Aliyev. Some 60 people attend Shabbat services weekly, and 300 on the holidays. Two schools, entirely paid for by the government, serve 300 students. The sanctuary has some local touches — a central pulpit, Oriental carpets, stacks of the local Jewish newspaper, which is printed in Russian.

Yevdayev is originally from Red Village. His daughter now lives in Brooklyn. I ask him if Jews are leaving Red Village and Baku for Israel and elsewhere.

“They go; they come back, they go — it’s not a trend,” he said. “You’ll see.”

The main synagogue in Azerbaijan’s Jewish community, known as Red Village, bears Persian rugs on its floors and decoratively carved wood throughout. It is one of three active synagogues in the town of 4,000 people. Photo by Rob Eshman

The next day, I saw. Our bus of some 30 conference participants followed a new highway north from Baku into the foothills of the Caucasus.

Quba is a medium-sized city, surrounded by pear and apple orchards. In 1730, the Khan Huseyn Ali decreed that Jews could own property in his district. Their settlement, Red Village, resembles a more prosperous version of the many small towns we had passed en route.

“There are many Jewish billionaires,” our tour guide informed us on the way up.

He wasn’t kidding. Since independence, Azeri Jews have flourished in business, especially in Russia, and they have spent millions restoring the old village, even buying up properties there as a link to their past. The soccer field and park look new, the stone, brick and wood homes refurbished. It was quiet — we arrived on Shabbat, when the cafes, restaurants and small businesses were closed. Azerbaijan’s Jews are as traditional, and as secular, as its Muslims.

Inside Red Village’s main synagogue, services were just letting out. There was a cacophony of kids and young men. The only sign that we were in the exotic East: Visitors are asked to remove their shoes, as in a mosque. The floor of the shul’s rich wooden interior is covered in Persian carpets.

Boris Simanduyen, chairman of the community, told us that until the Bolshevik Revolution, the town had 13 synagogues. Back then, the village was called Krasnaya Sloboda (Red Settlement) in Russian and had 18,000 residents. Now, Red Village has a Hebrew school with 60 students and three synagogues. President Aliyev’s administration pays for the heating oil for them all.

Simanduyen is a serious elderly man who speaks not a word of English or Hebrew. Through an interpreter he told me the town receives many visiting Jewish groups, people like me who can’t quite believe such a place exists. As if to offer more evidence, he called over a teenage boy who opened a prayer book and recited a Hebrew prayer at a breakneck pace.

Outside the synagogue, we ran into a group of high-spirited boys, most wearing kippot. They posed for pictures, and shouted back “hello,” and “Shabbat shalom!” to our own greetings.

“Our neighbors say, ‘Why do you send oil to Israel,’ ” our guide, a Shiite, said, summarizing the Azeri attitude toward the Jewish minority. “We say, ‘The Jews are our brothers. They make a big contribution to the economy and culture of Azerbaijan.’ ”

That contribution is beginning to extend beyond the historic. A subtext of every speech we heard and visit we made was that Azerbaijan is seeking international support for its ongoing conflict with Armenia, which, in 1992, fought a brutal war with Azerbaijan over the disputed territory of Nagorno-Karabakh and has occupied that region since, in contravention of United Nations resolutions.

The continued occupation by force of some 20 percent of Azerbaijan’s territory consumes Azeri political discourse.

Near Quba, we pulled into a brand-new memorial complex of angular concrete and polished granite. Just beside it lay mounds of human skulls, recently excavated at the site of a massacre in 1918 of Muslim and Jewish residents by Bolshevik, Armenian and Christian forces. About 600 people were slaughtered by what our guide referred to as “Armenian gangsters.” The exhibit looked as if it had been airlifted directly from Yad Vashem.

In a meeting with Yevda Abramov, Azerbaijan’s sole Jewish parliamentarian, a big, deep-voiced Mountain Jew, we asked what message he wanted us to convey to American Jews.

“Please present the Armenian holocaust against us,” he said, then launched into a tirade on the “double standard” in how the world only cares about Israel’s occupation of Palestinian territory and ignores Armenia’s occupation of Azeri land.

Abramov raised his considerable voice. “The Armenian lobby prevents a just solution!” he said.

Of course, as in any tribal-religious-political conflict, the Armenians level their own accusations of land grabs and massacres. Azerbaijan, a country suffering from occupation, has allied itself with Israel, a country trying to extricate itself from being an occupier. The situation is not as ironic as it seems when you look at a map. Squeezed between Vladimir Putin’s neo-imperialist Russia to the north and Iran’s mullahs to the south, Azerbaijan sees in Israel a natural ally also ringed by enmity.

Israeli military technology and know-how is helping the once-poor Azerbaijan develop an army that can credibly threaten to take Nagorno-Karabakh back by force. In exchange, one expert told me, Israel gets to park drones and perhaps even launch operations right at the edge of the Iranian border.

“The Almighty presented us with oil, but not with neighbors,” Abramov said with a sigh.

And, just like Israel, Azerbaijan’s historic feud with its neighbor constantly threatens to keep dragging it into the bloody past, even as it carves out a uniquely promising future.

Political strife has challenged Azerbaijan’s journey to full-fledged democracy. Earlier this year, the government announced the results of its presidential election before it was held, making the country a punch line on “The Daily Show.” But in their 21 years at the helm, the Aliyevs have transformed a communist police state into a catpitalist, struggling semi-democracy — all the while negotiating a treacherous neighborhood.

“Don’t write off Azerbaijan just yet,” Matthew Bryza, former United States ambassador to Azerbaijan, told CNN last month.

Indeed, the country’s long history of tolerance may yet ensure its success.

In Baku, I told Ambassador Iskandarov how much I’d enjoyed the local food, a blend of Persian and Turkish cuisines. He told me I should really visit the best Azerbaijani restaurant in the United States — Baku Palace, in Brooklyn. Its owner, he said, is a Jew.