The Act of Security 1704 (also referred to as the Act for the Security of the Kingdom) was a response by the Parliament of Scotland to the Parliament of England's Act of Settlement 1701. Queen Anne's last surviving child, William, Duke of Gloucester, had died in 1700, and both parliaments needed to find a Protestant successor. The English Parliament had settled on Electress Sophia of Hanover, granddaughter of King James VI and I, without consulting the Scottish Parliament.
The response of the Scottish Parliament was to pass a bill in 1703 requiring that, on the death of Queen Anne without issue, the three Estates of the Parliament were to appoint a Protestant successor from the descendants of the Scottish kings, but not the English successor unless various economic, political and religious conditions were met. The bill was refused Royal Assent by the Lord High Commissioner to the Parliament of Scotland.
The following year, 1704, the bill became an Act after the Scottish Parliament refused to raise taxes and sought to withdraw troops from the Duke of Marlborough's army in the War of the Spanish Succession unless Royal Assent was given.
The English Parliament retaliated with the 1705 Alien Act, threatening to cut trade and free movement between the two countries, unless negotiations opened leading either to the repeal of the Act of Security, or (as in the event happened) to the Act of Union in 1707. The end result was the Union of England and Scotland into the Kingdom of Great Britain, approximately one hundred years after the Union of the Crowns.