In the aftermath of the Long Turkish War, a large number of refugees settled in the area Senj on the Holy Roman military frontier with the Ottoman Empire. The refugees swelled the ranks of Uskoks, a type of irregular militia that conducted cross border raids upon the Ottomans. Apart from their raiding activities, the Uskoks did not shy away from piracy, attacking ships without regard towards the ethnic background or religious affiliation of their crews. In 1606, the Ottomans and Holy Roman Empire signed the Treaty of Zitva Torok which prohibited cross border raiding across the two states. In 1615, the treaty was renewed, prompting more Uskoks to turn towards piracy in the Adriatic Sea. Their activities had negatively impacted the mercantile interests of the Republic of Venice since as far as 1564, which was already aiming to expand its territory towards Habsburg Istria. Venice hired mercenaries in the Kingdom of England and the Dutch Republic, launching blockade of Holy Roman, Adriatic ports. On 20 December 1615, the blockade escalated into the Uskok War with a Venetian invasion of the coastal areas. The Spanish Viceroy of Naples Pedro Téllez-Girón, 3rd Duke of Osuna, intervened into the conflict on the Imperial side, without Spanish approval. The Habsburgs failed to mount an appropriate response as the country faced an internal power struggle. Nevertheless the Venetians were decimated by disease, failing to exploit their numerical superiority. Although negotiations continued throughout the conflict, an agreement was only reached in 1617 with the aid of Spanish, Papal and French mediation.
Treaty
On 26 September 1617, Imperial diplomat Karl von Harrach became the cosignatory of the Treaty of Madrid along with Venetian ambassadors Giustiniani and Contarini, ending the conflict between the two states. The Venetians agreed to the withdrawal of their troops from Imperial territories, while also discharging the English and Dutch mercenaries. The Habsburgs in their turn, agreed to transfer the Uskoks further to the north east by June 1618, while also cutting the number of their forces to 1,000 men. A regular Habsburg garrison was to be established in Senj. The Duke of Osuna remained defiant of both the treaty and the wishes of the Spanish crown, unilaterally continuing his maritime campaign. He was eventually arrested by Spanish authorities in 1620, and convicted of conspiring to become an independent ruler of Naples. Uskoks were either expelled from the empire or resettled deeper into Croatia. The few families that were allowed to stay were closely monitored, ending the Uskok piratical reign.