In order to be elected king after the death of his father, Frederick conceded significant influence to the nobility. As king, he fought two wars against Sweden. He was defeated in the Dano-Swedish War of 1657–1658, but attained great popularity when he weathered the 1659 Assault on Copenhagen and won the Dano-Swedish War of 1658–1660. Later that year, Frederick used his popularity to disband the elective monarchy in favour of absolute monarchy, which lasted until 1848 in Denmark. He married Sophie Amalie of Brunswick-Lüneburg, with whom he fathered Christian V of Denmark.