It may not be the kind of place you would expect to stumble upon a mosque, but Muslims have lived among the forests and lakes of Lithuania for more than 600 years - showing that tolerance reigned here in the Middle Ages, even when religious strife was rampant in other parts of Europe.

At first glance, the square, wooden building looks like thousands seen in villages all over the Baltic. Neat timber slats, wood-framed windows, a tin roof.

But at the apex of the roof, instead of a point there is a small glass turret, topped with an onion dome of the kind you might see on a local church. Then, on top of the onion, stands a small crescent.

This is the most European-looking mosque you will ever come across.

If it looks completely at home in this northern European setting, that's because a mosque has stood here, roughly 20 minutes' drive south-west of the Lithuanian capital, Vilnius, since 1558.

There is a clue in the name of the village, Keturiasdesimt Totoriu. It means Forty Tatars, and legend has it that this is the number of Tatar families that settled here more than 600 years ago, at the invitation of the Lithuanian Grand Duke, Vytautas.

Image caption The mosque was rebuilt in 1901, after it burned down

The Grand Duchy, with its deep pagan roots, faced a constant threat from its aggressive Christian neighbours to the west, the Teutonic Knights.

So in 1398, returning from a military campaign near the Black Sea, Vytautas brought with him a large number of Muslim Crimean Tatars and a small group of Karaite Jews to help defend Lithuanian territory.

Sure enough, 12 years later the Teutonic Knights went to war with Poland and Lithuania and the Tatars and Karaites fought alongside Vytautas at the Battle of Grunwald (between Warsaw and Gdansk) in which the crusaders were resoundingly defeated.

As a reward for their support, Vytautas gave the Muslims land and complete religious freedom - and this was at a time when both the Sephardic Jews, and Europe's oldest Muslim community, the Moors, were being driven out of Spain.

Vytautas the Great, ruler of the Grand Duchy of Lithuania (1392-1430)

Image copyright Alamy

"Vytautas is highly revered among us. He did not order us to forget the Prophet... We swore an oath upon our swords to love the Lithuanians when the fate and destiny of war brought us to their homeland and they said... 'This land, these waters... will be shared between us'"

Tatar petition sent in 1519 to Grand Duke of Lithuania and King of Poland, Sigismund I

Today about 120 people who live in Keturiasdesimt Totoriu are Tatars, with many claiming to be direct descendants of the founding Crimeans.

"It is because of Vytautas we are here, but we know we are Crimean Tatars," says Fatima Stantrukova, a 75-year-old former teacher of Russian literature.

The oldest identifiable grave in the mosque's cemetery belongs to a certain "Allahberdi" who was buried here in about 1621.

The Tatar population in Lithuania continued to grow and spread to the south and west. Once there were dozens, possibly hundreds of Tatar mosques in villages between Vilnius, the Belarusian capital, Minsk, and the Polish city of Bialystok.

There were still 25 in Lithuania on the eve of World War One. Now there are three - in Keturiasdesimt Totoriu and the nearby villages of Raiziai and Nemezis. Four others are split between the Polish settlements of Kruszyniani and Bohoniki and the Belarusian towns of Navahrudak and Iwie.

Image caption Graves at the mosque in Nemezis

It was the Tatar language that disappeared first, apparently in the early part of the 18th Century.

"It came to pass that the 'spiders of forgetfulness' spread their webs over their customs and their tongues with the passing of the ages," wrote the Russian Tatar Orientalist Muhammad Murad al-Ramzi, in the 19th Century.

"Yet, despite that, they have never lost their faith in Islam, though they have no scholarly knowledge of the faith."

What little Islamic knowledge was left, took a further blow in the 20th Century.

"The Soviet period was the worst. All the religious leaders and people of any knowledge were either killed or sent into exile into the farthest reaches of Siberia. Books and archives were burnt. Mosques were closed and destroyed. Communities were closed. Islam was forbidden," says another descendant of the Crimeans who arrived with Vytautas, the Grand Mufti of Lithuania, Ramadan Yaqoob.

Image caption Baltic Tatars traditionally had two names - Ramadan Yaqoob (the Muslim name he has always used with family and close friends) is officially Romas Jakubauskas

Yaqoob grew up knowing almost nothing about Islam, and was only exposed to it properly after the fall of the Soviet Union, when Muslim students began to arrive in the country. He felt an immediate connection with them, and was able with their help to study in Lebanon and Libya. The multicultural atmosphere of Lebanon was the perfect place to train to lead a European Muslim community, he says.

Despite a revival of interest in religion among some young Tatars, none of the mosques opens for the five daily prayers. Even in Keturiasdesimt Totoriu, where a third of the population is Muslim, the mosque only opens for special religious occasions.

But in addition to these seven surviving Baltic Tatar mosques, there is another many thousands of miles to the west - at 104 Powers Street in Brooklyn - which bears an uncanny resemblance.

"I used to go to the mosque, mainly with my family, for festivals like Eid," says Alyssa Ratkewitch, the mosque's vice-president, a third-generation Lipka Tatar - as Tatars from the Baltic are sometimes called - who traces her roots to the Belarusian town of Iwie.

"One of my earliest memories was the 'awful' wood panelling that decorates the interior of the mosque. So when I became vice-president, I planned to get rid of it, until an elder told me that the panels were there to remind them of the mosques they had left behind in the Baltic."

The Brooklyn mosque - which opened in 1927 and is believed to be the oldest in New York - also no longer opens for daily worship. But it is crucial to the identity of the tiny Tatar community, just like the seven Tatar mosques still standing in Lithuania, Belarus and Poland.

"We did not let our mosques fall! During the [Soviet] time, our mosque was used in secret," remembers Fatima in Keturiasdesimt Totoriu.

"The imam and the community of the 1940s kept the mosque alive for us children.

"The mosques are all we have left."

Image caption Fatima in her prayer cap

Subscribe to the BBC News Magazine's email newsletter to get articles sent to your inbox.