In 1609, the Vyborg Treaty was signed by Sweden and Tsardom of Russia as a package of military agreements that were supposed to be mutually beneficial to both countries. It was signed by King Charles IX of Sweden and Vasili IV (also known as Vasily Shuisky) of Russia in the Swedish city of Vyborg, located on the Karelian Isthmus close to Russian territory. The treaty came at an unstable period in Russian history known as the Time of Troubles, where the death of Tsar Feodor I in 1598 led to decades of civil war. In 1605, following the death of de facto ruler Boris Godunov, Vasily Shuisky came to power, triggering a conflict with a pretender to the Russian throne, False Dmitry II. Additionally, Russia began fighting the Polish–Muscovite War following invasion of the country by the Polish-Lithuanian Commonwealth the same year. Sweden themselves were fighting against the Poles in the Polish–Swedish War, and viewed their eastward expansion into Russian lands as a security threat. The terms of the Vyborg Treaty stipulated that Sweden would supply a corps of mercenaries to Shuisky to fight False Dmitry II and the Poles, in exchange for Swedish control of the nearby strategic Korela Fortress, as well as its town Kexholm and the respective county. Shuisky agreed to the terms, but was an unpopular ruler with little power. Shortly after signing the Vyborg Treaty, Russia's fortunes began to rise, and Shuisky was forced out of power in 1610. A coalition between Swedish general Jacob de la Gardie and Russian princes launched the De la Gardie Campaign, effectively defeating False Dmitry II.
The Ingrian War was triggered in 1610 as the new stability of Russia led to increased resistance to Polish occupation and Swedish influence in the country. As the Poles were defeated in Moscow, Russia began to actively resist the Swedish influence as they sought to regain control over occupied territories, including the province of Ingria, which Sweden insisted on keeping based on Russia violating conditions in the Vyborg Treaty. Sweden constructed a fortress in Ingria at a strategic position at the confluence of the prominent Neva River and one of its tributaries, the Okhta River. The new fort was officially named Nyenskans, derived from the Swedish terms Nyen-, the name for the Neva, and -skans meaning "bastion", and was capable of housing 500 people. The Ingrian War ended in Swedish victory in 1617 after the signing of the Treaty of Stolbovo, resulting in Russia ceding the territories to Sweden. In 1632, the settlement of Nyen was developed across the Okhta from Nyenskans, which was granted town privileges and became the administrative centre of Swedish Ingria in 1642. By the mid-17th century, Nyen had prospered as a trading hub and had a population of around 2,000 people, making it much larger and wealthier than Swedish Ingria's new capital, Nöteborg. According to church records, the town's population was largely made up of Finns, secondarily Swedes, and some Germans. Around this time, Nyen's governor, John Geselia the Younger, banned Orthodox Christian Swedish subjects from settling in or near the town following tensions with Lutherans. The ban of Orthodox residents effectively cleansed Nyen of ethnic Russian, Izhorian, and Karelian inhabitants.
In 1656, Nyenskans was attacked by Russia during an invasion led by Pyotr Potemkin. The attack was repelled, but Nyen was badly damaged by the attack and Sweden moved the administrative centre of Swedish Ingria from Nöteborg to Narva.
In 1677, the defences of Nyenskans and Nyen were enforced by a ring of new fortifications consisting of lunettes with batteries and moats. By the end of the 17th century, Nyenskans entered its final form after it had been modernized by an extensive project led by engineer Heinrich von Soylenberg. The fort was expanded to house 600 people, converted into a star fort featuring five wooden and earthen bastions, two additional ravelins, crownworks along the bastions not pointing towards the rivers, and a smaller accompanying half-fort built on the opposite bank of the Neva. Upon the completion of the project, Nyenskans was thought by Sweden to be the most modern fortress in the world at the time. By the turn of the 18th century, numerous Swedish and Finnish suburban manors were built outside of the Nyen fortification ring. Most were along the Neva, some of which were located at a considerable distance from the city.
In 1700, danger of Russian invasion increased following the beginning of the Great Northern War, which resumed formal hostilities between Sweden and Russia. Reportedly, in October 1702, Sweden feared an imminent Russian invasion of Nyen, evacuating the city's population and burning it down to prevent the Russians from taking it.