As midnight approached on 27 July, scores of visitors to the Norwegian city of Tromsø – the largest non-Russian municipality north of the Arctic Circle – thronged to Mount Storsteinen, or “the mountain”, as it’s locally called. Some of the more intrepid midnight summiteers hiked a switch-backed trail through the woods along its flank; the most ambitious clambered nearly vertically to the summit. (I made a try, but I’d worn the wrong shoes.) Others were whisked upward by Fjellheisen, the mountain’s popular aerial tramway.

At the top, the assembled crowd earnestly awaited the disappearance of the Sun, which had not been absent from Tromsø’s sky for two whole months. Before our eyes, it vanished, regally swathed in brilliant Arctic pink and violet and orange. And an hour later it reappeared, commencing Tromsø’s gradual shortening of days until the start of the midwinter interval of absolutely no sunlight at all.

Curiously, the sizeable Muslim population of Tromsø took little notice of the spectacle. Whenever I mentioned the impending sunset to a Muslim resident, the response was some version of a shrug. Behind this indifference lies an interesting story of cultural displacement, nostalgia, adjustment and endless debate about niceties of solar astronomy.

You may also be interested in:

• The Europeans who chose mystical Islam

• The religion passed down from Vikings

• The synagogues preserved by Muslims

No major religion’s daily ritual observances are tied more closely to the movement of the Sun than Islam’s. “As a child, I watched for sunrise and sunset,” said Hussein Abdi Yusuf nostalgically, “and I listened five times a day for the prayer calls from the mosque.” Yusuf is the imam of Al Rahma, the smaller of Tromsø’s two mosques, located in a plain green house that the congregation has rented since 1991. Soft-spoken and affable, Yusuf grew up in a religious family in Somalia where, as he puts it, everything revolved around the times of prayer, which are determined by sunrise and sunset. Under normal circumstances, the first prayer of the five each day (Fajr) precedes sunrise; the last (Isha) follows shortly after Maghrib, the sunset prayer.

Other members of Tromsø’s Islamic community told me similar stories of displacement from the orderly dawns and dusks of their childhoods. Mansoor Waizy, who is on the governing board of Alnor Senter, the larger of the two mosques, spoke of uprooting himself from Kabul to Germany, and how in Kabul “you divided the day according to the prayer times”, but in Germany the rhythm of the workday took precedence.

“In Germany, the change was frustrating,” said Waizy, “but at least the sun still rose and set.”

In 2007, he moved to Tromsø and recalls how disorienting it was to pray Maghrib with the sun still high in the sky. “I prayed in a really confused way,” he said.

The solution to undoing, or at least mitigating, this confusion, has been perhaps the foremost faith-related challenge for Norway’s Arctic Islamic communities. (In addition to the two Tromsø mosques, there’s a small mosque in the city of Alta, to the east and slightly further north, and another in Hammerfest, even further north.) What’s an acceptable compromise when the Sun behaves in a manner incompatible with the fundamental principles of the Islamic prayer schedule?

“We’re still trying to figure it out,” answered Ole Martin Risan, a Tromsø-born convert to Islam, when we chatted in Alnor Senter’s kitchen, two blocks south of Al Rahma near the heart of Tromsø’s tourist district.

Alnor Senter occupies an unprepossessing but spacious former dance studio on a steeply sloped street that descends toward Tromsø’s waterfront. Spacious as it is, the mosque can seem small at prayer time: during the Friday afternoon and evening prayer services I attended, the prayer room was bursting at the seams. On the busiest prayer day of the year, Eid al-Fitr, the holiday that marks the end of Ramadan, the assembled congregation is so large – approaching triple digits – that Alnor Senter and Al Rahma join forces and worship together at a local municipal gymnasium that’s normally the home of the Tromsø Storm basketball team.

The problem of accommodating worshippers is driven by two factors: tourism and immigration, both of which are expanding Tromsø’s permanent and transient Muslim community.

“In the last few years [tourism has] been blowing up,” said Nadia Hakmi, who was born into a Muslim family in Tromsø and works in the busy cruise-ship sector of Tromsø’s hospitality industry. Tromsø is marketed heavily in South-East Asia as a wilderness outpost where the skies blaze with auroras and the streets are roamed by “ice bears” (polar bears). Visiting Islamic tourists, including Halal tourism groups, often drop in at Alnor Senter to keep up their daily routine of prayer.

“Sometimes the prayer room gets so crowded [with tourists] that the congregation overflows into the neighbouring classrooms,” said Siv Samira Kofoed, a long-time Alnor Senter congregant.

Tourism is at the heart of the local economy, so much so that Tromsø has one of the lowest unemployment rates in Norway, according to Yusuf. It’s this prosperity, in part, that draws immigrants from countries like Somalia and Ethiopia who are fleeing war and poverty and find a measure of stability and opportunity in Europe’s far north. After prayer at Alnor Senter, I chatted with several young men enrolled at the University of Tromsø. There they were availing themselves of a wealth of career-building opportunities. Some said they expected to move south to Oslo or Stockholm once they earned their degrees; others envisioned praying with their children in Alnor Senter’s prayer room.

Those who remain will continue the tradition of seeking to reconcile traditional Islamic daily prayer with the peculiarities of Arctic astronomy. At Alnor Senter, the effort goes back to the mosque’s founding in 2006 by another Tromsø-born convert, Sandra (Maryam) Moe. Moe and other leaders of the mosque contacted Islamic scholars in Saudi Arabia, Egypt and Kuwait, posing the question of the midnight sun and its bearing on the timing of daily prayer. The scholars issued a fatwa (a legal opinion) offering three choices: coordinate prayer times with the nearest country where the Sun rises and sets regularly throughout the year; allow individual mosque members to coordinate with their countries of origin; or sync the Tromsø schedule to sunrise and sunset in the holy city of Mecca, the birthplace of the prophet Muhammad.

Both Tromsø mosques agreed to the last option, at least provisionally: “Until we could find something better,” Waizy said. He and others believed that the proposed arrangement didn’t fully address their new identity as Norwegian Muslims. It simply imposed a schedule from a distant locale.

It’s always been agreed that no decision would be final

The search for a better solution took a turn in April of this year when the imams of the two mosques travelled to Sweden to debate the prayer-time issue, and the separate but related question of fasting during Ramadan, with Islamic scholars from Denmark, Sweden and Finland, as well as representatives from the communities in Alta and Hammerfest.

After much deliberation, the scholars made a suggestion, essentially proposing to localise the two afternoon prayers – Zuhr and Asr – by determining the daily highest position of the Sun as observed from each individual Arctic mosque. (In winter, this observation would be indirect, via calculation, but it would still be tied to each individual location.) As for the earlier and later prayers each day, the schedule would introduce an adjustment, keyed to Mecca sunrise and sunset, to round out a balanced daily worship schedule.

Since April, this synthesis of local and Mecca times has been the official system for prayer in Tromsø. Still, it’s a work in progress. As Hakmi explained, “It’s always been agreed that no decision would be final. The process is ongoing.” And in fact, in mid-December 2019, the Tromsø mosques will host a follow-up conference specifically to revisit the schedule tentatively developed in April.

Not everyone adheres to the new schedule: a few congregants continue to follow Mecca time, while others remain attached to their countries of origin – Yusuf pointed out two members of Al Rahma who time their prayers to sunrise and sunset in Paris, their home town.

We were on the back steps of Al Rahma just after evening prayer, as lingering worshippers chatted in the small lot behind the green house. I asked Yusuf whether the prospect of the sunless winter ahead disheartened him. He responded that he’d grown used to it. He’d had a long journey. After fleeing violence in Somalia, he’d spent four years in Harstad – another small northern Norwegian town, south of Tromsø but still north of the Arctic Circle – before taking up residence as Al Rahma’s imam.

In just a few months a melancholy solar farewell would take place atop Mount Storsteinen, and the Sun would not rise again in Tromsø until next year. Yusuf looked up at the sky, which already had a subtle feel of early twilight. “This country gives us something different,” he said. “We have peace in this country. That means a lot.”

Join more than three million BBC Travel fans by liking us on Facebook, or follow us on Twitter and Instagram.

If you liked this story, sign up for the weekly bbc.com features newsletter called "The Essential List". A handpicked selection of stories from BBC Future, Culture, Worklife and Travel, delivered to your inbox every Friday.