Jews have lived in Morocco for thousands of years, at least since the 6th-century BCE, after the Babylonian Exile of the Jews from Israel. In the 1st century, after Jerusalem was destroyed by the Romans in 70CE, many Jews fled to Morocco. Their numbers increased significantly after the Jews were expelled from Spain in 1492, as part of the Spanish Inquisition.
Jews developed close relationships with the indigenous Berbers through trade and there was a great deal of cross cultural influence. Many Berbers converted to Judaism and Moroccan Jewish ritual took on some elements of Berber religion. Jews and Berbers fought together against the Muslim Arab invaders in the 7th century.
Jews settled all over the country, with large communities in the major cities and were influential in the early development of Fez from the 9th to 11th century, when they prospered there. Later, their fortunes rose and fell depending on the tolerance levels of those in power.
Under Islamic law, Jews were allowed to practice their religion but were segregated in neighborhoods called mellah. The first mellah was established in Fez in the 15th century. Initially it was a fine area with beautiful buildings and an air of exclusivity, but over time, the mellah was viewed, from the outside, as an undesirable place of outcasts.
The Jewish population in Morocco peaked at more than 200,000 in the first half of the 20th century but the numbers declined steadily after the founding of Israel and now there are only around 5,000 Jews in Morocco, mostly in Casablanca.
Today, the mellah of Fez makes an interesting visit. You can see the synagogue and the cemetery and the distinct Andalusian architecture, with balconies facing out onto the alleys, very different than the typical medina buildings, with windows opening onto inner courtyards. Of late, this area is overrun with false guides, who relentlessly hassle tourists to buy their services. Avoid this by entering the mellah with a licensed guide booked through a reputable tour operator.