Since $(a,p)=1$ this is the same as solving $(xa^{-1})^2\equiv-1\bmod{p}$ or in other words solving $y^2\equiv-1\mod{p}$.