The famous $n$-queens problem asks how many ways there are to place $n$ queens on an $n times n$ chessboard so that no two queens can attack one another. The toroidal $n$-queens problem asks the same question where the board is considered on the surface of the torus and was asked by P{o}lya in 1918. Let $Q(n)$ denote the number of $n$-queens configurations on the classical board and $T(n)$ the number of toroidal $n$-queens configurations. P{o}lya showed that $T(n)>0$ if and only if $n equiv 1,5 mod 6$ and much more recently, in 2017, Luria showed that $T(n)leq ((1+o(1))ne^{-3})^n$ and conjectured equality when $n equiv 1,5 mod 6$. Our main result is a proof of this conjecture, thus answering P{o}lyas question asymptotically. Furthermore, we also show that $Q(n)geq((1+o(1))ne^{-3})^n$ for all $n$ sufficiently large, which was independently proved by Luria and Simkin. Combined with our main result and an upper bound of Luria, this completely settles a conjecture of Rivin, Vardi and Zimmmerman from 1994 regarding both $Q(n)$ and $T(n)$. Our proof combines a random greedy algorithm to count almost configurations with a complex absorbing strategy that uses ideas from the recently developed methods of randomised algebraic construction and iterative absorption.