[proofplan]
We compare the norm $p_n^2 - Dq_n^2$ of the convergents $p_n/q_n$ of $\sqrt{D}$ with the complete quotients in the periodic continued fraction expansion. The complete-quotient identity shows that the convergent at the end of one period has norm $(-1)^\ell$, so an odd period gives a solution to the negative Pell equation. Conversely, any solution gives an exceptionally good rational approximation to $\sqrt{D}$, hence a convergent by Legendre's theorem; the complete-quotient identity then forces the relevant convergent to occur at the end of an odd number of full periods, so the fundamental period length is odd.
[/proofplan]
[step:Define the convergents and complete quotients of $\sqrt{D}$]
Let
\begin{align*}
\sqrt{D} = [a_0; a_1, a_2, a_3, \dots]
\end{align*}
be the simple continued fraction expansion of $\sqrt{D}$, with minimal period $\ell$ after $a_0$. Define the convergent numerator and denominator sequences $(p_n)_{n \geq -2}$ and $(q_n)_{n \geq -2}$ by
\begin{align*}
p_{-2} &= 0, & p_{-1} &= 1, & p_n &= a_n p_{n-1} + p_{n-2}, \\
q_{-2} &= 1, & q_{-1} &= 0, & q_n &= a_n q_{n-1} + q_{n-2}
\end{align*}
for every integer $n \geq 0$. Thus
\begin{align*}
\frac{p_n}{q_n}
\end{align*}
is the $n$th convergent of $\sqrt{D}$.
For the complete quotients, define integer sequences $(P_n)_{n \geq 0}$ and $(Q_n)_{n \geq 0}$ by
\begin{align*}
P_0 &= 0, & Q_0 &= 1, \\
P_{n+1} &= a_n Q_n - P_n, & Q_{n+1} &= \frac{D - P_{n+1}^2}{Q_n}.
\end{align*}
Then the $n$th complete quotient is
\begin{align*}
\alpha_n = \frac{P_n + \sqrt{D}}{Q_n}.
\end{align*}
We use the [Complete-Quotient Norm Formula for Periodic Continued Fractions](/theorems/complete-quotient-norm-formula-for-periodic-continued-fractions) with the indexing convention just defined. In precisely this convention, applied to the nonsquare integer $D > 0$ and to the simple continued fraction of $\sqrt{D}$, it asserts that the recursively defined quantities $P_n$ and $Q_n$ are integers, that $Q_n > 0$ for every $n \geq 0$, that
\begin{align*}
p_n^2 - Dq_n^2 = (-1)^{n+1}Q_{n+1}
\end{align*}
for every $n \geq 0$, and that $Q_m = 1$ with $m > 0$ precisely when $m$ is a multiple of the minimal period $\ell$. The hypotheses of that result are exactly the hypotheses already in force here: $D$ is a positive nonsquare integer, the expansion is the simple continued fraction expansion of $\sqrt{D}$, and the sequences $p_n,q_n,P_n,Q_n$ use the displayed recurrence and indexing convention. The explicit restatement fixes the indexing dependency: every later use of the theorem refers to this displayed convention.
[/step]
[step:Use the end-of-period convergent when the period is odd]
Assume that $\ell$ is odd. Apply the complete-quotient norm identity with $n = \ell - 1$. Since $Q_\ell = 1$, we obtain
\begin{align*}
p_{\ell-1}^2 - Dq_{\ell-1}^2
&= (-1)^\ell Q_\ell \\
&= -1.
\end{align*}
Because $p_{\ell-1}, q_{\ell-1} \in \mathbb{Z}$, the pair
\begin{align*}
(x,y) = (p_{\ell-1}, q_{\ell-1})
\end{align*}
is an integer solution of
\begin{align*}
x^2 - Dy^2 = -1.
\end{align*}
Thus an odd period implies solvability of the negative Pell equation.
[/step]
[step:Convert an integer solution into a convergent of $\sqrt{D}$]
Conversely, suppose that $(x,y) \in \mathbb{Z}^2$ satisfies
\begin{align*}
x^2 - Dy^2 = -1.
\end{align*}
Since $D > 0$, we cannot have $y = 0$. Replacing $(x,y)$ by $(|x|, |y|)$ if necessary, we may assume $x > 0$ and $y > 0$, because the equation depends only on $x^2$ and $y^2$.
From $x^2 - Dy^2 = -1$, we have
\begin{align*}
D y^2 - x^2 = 1.
\end{align*}
Factoring the left-hand side gives
\begin{align*}
(y\sqrt{D} - x)(y\sqrt{D} + x) = 1.
\end{align*}
Since $y\sqrt{D} + x > 0$, this yields
\begin{align*}
0 < y\sqrt{D} - x = \frac{1}{y\sqrt{D} + x}.
\end{align*}
Dividing by $y$ gives
\begin{align*}
0 < \sqrt{D} - \frac{x}{y}
= \frac{1}{y(y\sqrt{D} + x)}.
\end{align*}
Because $x^2 = Dy^2 - 1$, we have $x < y\sqrt{D}$, and therefore
\begin{align*}
y\sqrt{D} + x > 2x.
\end{align*}
Also $x^2 = Dy^2 - 1 \geq y^2$ unless $D=1$, and $D=1$ is excluded because $D$ is not a square. Hence $x \geq y$ for $D \geq 2$, so
\begin{align*}
y\sqrt{D} + x > 2y.
\end{align*}
Therefore
\begin{align*}
0 < \sqrt{D} - \frac{x}{y}
= \frac{1}{y(y\sqrt{D} + x)}
< \frac{1}{2y^2}.
\end{align*}
By [Legendre's Theorem on Continued Fractions](/theorems/legendres-theorem-on-continued-fractions), any rational number $r/s$ in lowest terms satisfying
\begin{align*}
\left|\sqrt{D} - \frac{r}{s}\right| < \frac{1}{2s^2}
\end{align*}
is a convergent of $\sqrt{D}$. Let $\gcd(x,y)$ denote the greatest common divisor of the integers $x$ and $y$. Since $\gcd(x,y)=1$ follows from $x^2 - Dy^2 = -1$, the rational number
\begin{align*}
\frac{x}{y}
\end{align*}
is in lowest terms. Hence there exists an integer $n \geq 0$ such that
\begin{align*}
\frac{x}{y} = \frac{p_n}{q_n}.
\end{align*}
Here the cited result is [Legendre's Theorem on Continued Fractions](/theorems/legendres-theorem-on-continued-fractions).
[guided]
Assume that $(x,y) \in \mathbb{Z}^2$ satisfies
\begin{align*}
x^2 - Dy^2 = -1.
\end{align*}
The case $y = 0$ would give $x^2 = -1$, impossible in $\mathbb{Z}$, so $y \neq 0$. Since the equation only involves $x^2$ and $y^2$, replacing $(x,y)$ by $(|x|,|y|)$ gives another solution; hence we may assume $x > 0$ and $y > 0$.
Rearranging the equation gives
\begin{align*}
Dy^2 - x^2 = 1.
\end{align*}
Factoring in $\mathbb{R}$ gives
\begin{align*}
(y\sqrt{D} - x)(y\sqrt{D} + x) = 1.
\end{align*}
The second factor is positive, so the first factor is positive and
\begin{align*}
0 < y\sqrt{D} - x = \frac{1}{y\sqrt{D} + x}.
\end{align*}
After dividing by the positive integer $y$, we obtain
\begin{align*}
0 < \sqrt{D} - \frac{x}{y}
= \frac{1}{y(y\sqrt{D} + x)}.
\end{align*}
Because $x^2 = Dy^2 - 1$, we have $x < y\sqrt{D}$. Also $D \geq 2$, since $D \in \mathbb{N}$ is positive and not a square. Therefore $x^2 = Dy^2 - 1 \geq y^2$, so $x \geq y$. Combining these inequalities gives
\begin{align*}
y\sqrt{D} + x > 2y.
\end{align*}
Substituting this lower bound into the denominator yields the approximation estimate
\begin{align*}
0 < \sqrt{D} - \frac{x}{y}
= \frac{1}{y(y\sqrt{D} + x)}
< \frac{1}{2y^2}.
\end{align*}
We now apply [Legendre's Theorem on Continued Fractions](/theorems/legendres-theorem-on-continued-fractions). This is the reason for proving the sharp-looking bound with the factor $1/2$: Legendre's theorem converts exactly this quality of approximation into membership in the convergent sequence. Its input is a reduced rational number $r/s$ with $s > 0$ satisfying
\begin{align*}
\left|\sqrt{D} - \frac{r}{s}\right| < \frac{1}{2s^2}.
\end{align*}
Here $r=x$ and $s=y$. The denominator condition holds because $y>0$, and the approximation estimate was proved above. The rational number is reduced: if an integer $d \geq 1$ divides both $x$ and $y$, then $d^2$ divides $x^2 - Dy^2 = -1$, so $d=1$. Thus Legendre's theorem implies that there is an integer $n \geq 0$ such that
\begin{align*}
\frac{x}{y} = \frac{p_n}{q_n}.
\end{align*}
[/guided]
[/step]
[step:Force the convergent to occur after an odd number of full periods]
For the integer $n \geq 0$ found above, the equality $x/y = p_n/q_n$ and the coprimality of numerator and denominator give
\begin{align*}
x = p_n, \qquad y = q_n.
\end{align*}
Substituting into the negative Pell equation gives
\begin{align*}
p_n^2 - Dq_n^2 = -1.
\end{align*}
Using the complete-quotient norm identity,
\begin{align*}
p_n^2 - Dq_n^2 = (-1)^{n+1}Q_{n+1},
\end{align*}
we obtain
\begin{align*}
(-1)^{n+1}Q_{n+1} = -1.
\end{align*}
Since $Q_{n+1}$ is a positive integer, this forces
\begin{align*}
Q_{n+1} = 1
\end{align*}
and
\begin{align*}
(-1)^{n+1} = -1.
\end{align*}
Thus $n+1$ is odd. By the periodic complete-quotient criterion for $\sqrt{D}$, the equality $Q_{n+1}=1$ with $n+1>0$ implies that $n+1$ is a multiple of the minimal period $\ell$. Therefore there exists $k \in \mathbb{N}$ such that
\begin{align*}
n+1 = k\ell.
\end{align*}
Since $n+1$ is odd, the product $k\ell$ is odd. Hence $\ell$ is odd.
We have proved both directions: the negative Pell equation has an integer solution exactly when the continued fraction period length of $\sqrt{D}$ is odd.
[/step]