MARRAKECH, Morocco — To an outsider, nothing seemed normal about this night, as Muslims were welcomed by the Jewish community to celebrate Ramadan at their synagogue, the members of the two faiths meeting in stark contrast when set against the religious conflicts that plague the region.

But to the Jews and Muslims of Marrakech, this was a Ramadan tradition, as 100 of them gathered at sunset for Iftar, the dinner that breaks the daily fast during the Muslim holy month.

Before the Muslims could eat, however, first they had to pray. Here, they did so while standing before the ark that holds the sacred Torah scrolls. The Muslim men bowed their heads and knelt down on their knees in chants of “Allahu Akbar,” meaning, “God is the greatest.”

To an American onlooker, this scene in late June seemed earth-shatteringly out of the ordinary. But to the Muslims and Jews gathered here, it was a reminder of the 2,000-year-old ties that bind their communities together.

Before the Iftar, Muslim men pray in at the Synagogue Beth El in Marrakech while standing before the ark that holds the sacred Torah scrolls on June 18, 2017. Yardena Schwartz / for NBC News

Today, Jews account for less than 3,000 of Morocco’s 35 million residents — a small fraction of the nearly 300,000 who lived here before the establishment of Israel in 1948. Still, that tiny figure makes Morocco home to the largest Jewish population in the Arab world. And unlike other Arab countries, which essentially expelled their Jewish communities around the time of Israel’s establishment, the Jews of Morocco were not forced out when Israel declared its independence.

To be sure, there were isolated cases of violence against Jews in Morocco during this time. For example, in June 1948, two days of anti-Jewish rioting killed 44 people and wounded some 60 others. Still, attacks on the Jewish community were mild compared to other Arab countries. In Iraq, Egypt, Yemen, Algeria and Libya, for example, government-sanctioned anti-Jewish policies led once-large Jewish communities to dwindle to zero.

One of the most infamous attacks occurred in Iraq before Israel’s establishment, in June 1941, when over 900 Jewish homes were destroyed and 180 Jews were killed, including women and children, in a gruesome pogrom known as the Farhud.

Related: Muslim Fundraiser to Repair Jewish Cemetery Raises $100k

“Jews in Morocco saw the writing on the wall,” said Robert Satloff, director of the Washington Institute for Near East Policy, who spent two years living in Morocco while researching his book, "Among the Righteous: Lost Stories of the Holocaust's Long Reach into Arab Lands."

There was plenty of anti-Jewish sentiment in Morocco at the time, said Satloff, but compared to Jews in other Muslim-majority countries, the Jews of Morocco were relatively better off. “They weren’t stringing Jews from street posts like they were in Iraq."

Let our news meet your inbox. The news and stories that matters, delivered weekday mornings. This site is protected by recaptcha

Most of Morocco’s Jews, he said, left not because they were expelled, but because they felt a growing sense that they had no future there. Morocco was under French and Spanish rule until 1956, and as the Arab nationalist movement gained momentum, hostility toward Jews increased, he said, leading the vast majority of Morocco’s Jews to move to Israel, France and Canada. “It was really this mix of feeling like there’s no future for us in Morocco, and knowing we have a homeland to go to,” he said, referring to Israel.

Yet despite the forces of Arabization and anti-Israel sentiments that gripped Morocco half a century ago, today Morocco is the only Arab country whose leader actively protects its Jewish community, said Satloff.

The Jews invited the Muslims from the community in Marrakech to join together for the Iftar, the dinner to break Ramadan, at Synagogue Beth El on June 18, 2017. Yardena Schwartz / for NBC News

André Azoulay is a Jewish senior adviser to the king of Morocco, Mohammed VI. He also served his father, King Hassan II. Explaining how Morocco has remained protective of its Jewish community despite the anti-Jewish sentiments that overtook other Muslim countries in the wake of Israel’s establishment, Azoulay said, “We are fighting for that. But it’s not just top down,” he said, referring to the king’s protection of the community. “It’s also bottom up. Judaism in Morocco is in the roots, the identity, the mindset of the Moroccan people.”

Indeed, in 2011 Judaism became enshrined in the nation’s constitution as a facet of Moroccan identity.

Azoulay cautioned against painting a sweeping brush of anti-Semitism across the Muslim world. After all, Arabs are a Semitic people as well, with Hebrew and Arabic sharing the same roots.

“You cannot find this kind of tragic situation that the Jews have unfortunately confronted in European countries,” he said, referring to the anti-Semitism that drove the Spanish Inquisition and the Holocaust. “You cannot find it in the same degree, the same motivation and the same scale in the Muslim world.”

Related: 'MuJews': Muslims and Jews Band Together Against Hate

And yet, he and others are careful not to sound too upbeat.

“Something that is unique is also fragile,” he warned.

Kamal Hachkar, a Moroccan Muslim historian and filmmaker who attended the Iftar dinner that night, called the flight of Morocco’s Jews “a big loss for Morocco,” adding, “It’s important to preserve the long history between Jews and Muslims here.”

Hachkar is well aware that not all Moroccans agree. His film, "Tinghir - Jerusalem, Echoes from the Mellah," documents the Jews who left Morocco for Israel. When it premiered at the Tangiers Film Festival in 2013, it was protested by members of Islamist and left-wing political parties, who called it “Zionist propaganda.” And yet, he took home the prize for Best First Film that night.

Explaining why the forces of unity have overcome the forces of division here, he said, “In Morocco, we prefer to live in a good state. We don’t want to live like in Iran, Iraq or Afghanistan.”

Those working to preserve this rare bubble of peace pay little attention to the naysayers.

“We are praying to the same God after all,” said Youssef Safine, a member of Mimouna, a Muslim organization that works to preserve Morocco’s Jewish history. Mimouna organized Iftar dinners throughout the country as a reflection of the age-old tradition here where Jews and Muslims invite each other to their religious festivities.

Related: Muslim, Jewish Communities in Michigan to Host Day of Service on Christmas

“Jews were here long before Islam,” said Safine, speaking in fluent Hebrew. The 24-year-old Muslim learned the Jewish language while growing up next to another synagogue in Marrakech, which was founded in 1492 and still hosts daily prayers.

Indeed, Jews have been living in the North African nation of Morocco since their exile from Jerusalem after the destruction of the first temple in 587 BC — before Christianity and Islam were born. A second wave came in 1492, when Jews fled the Spanish Inquisition, finding refuge and a thriving Jewish community in Spain’s southern neighbor.

Yael Eckstein, the VP of the International Fellowship of Christians and Jews, hands a child a bag full of food for Ramadan at Synagogue Slat Laazama. Yardena Schwartz / for NBC News

The ancient Jewish history of Morocco is deeply embedded in the identity of this Muslim-majority Arab country. So deeply that in 1940, when Morocco was under French rule and Paris fell to the Germans, the king of Morocco refused to cooperate with the Nazi regime. When the Nazis wanted to impose anti-Jewish laws and eventually send the nation’s Jews to concentration camps, King Mohammed V reportedly told the Nazis, “There are no Jews in Morocco. There are only Moroccans.”

Though France controlled Morocco throughout the Holocaust, during which the French government was complicit in the murder of French Jews, the Moroccan government was not known for sending Jews to concentration camps, or forcing them to wear yellow stars, surrender their property or their citizenship.

The day of the Iftar dinner, for the third consecutive year, volunteers from Mimouna partnered with the Jewish community to distribute 2,500 Ramadan meal packages to needy Muslims throughout the country. The packages, filled with enough food to last a week, were donated by the International Fellowship of Christians and Jews. The IFCJ, funded mainly by American Christians, began in 1983 with a focus on assisting the Jews of the former Soviet Union. It now conducts interfaith work around the world, but Morocco is the only Arab country in which it is doing so.

“The fact that the king has been so tolerant in reaching out to the Jewish community,” said Rabbi Yechiel Eckstein, president and founder of the IFCJ, “and the fact that there are Muslim youth taking part in these interfaith efforts, encourages us to help.”