[step:Check that the chord-and-tangent formulas remain inside $E(\mathbb{F}_p)$]Let $P,Q \in E(\mathbb{F}_p)$. If one of $P,Q$ is $O$, the chord-and-tangent law defines $P+O=O+P=P$, so the result lies in $E(\mathbb{F}_p)$.
Now suppose $P=(x_1,y_1)$ and $Q=(x_2,y_2)$ are affine points. If $x_1=x_2$ and $y_2=-y_1$, the line through $P$ and $Q$ is vertical, and the chord-and-tangent law defines
\begin{align*}
P+Q=O.
\end{align*}
This point belongs to $E(\mathbb{F}_p)$.
In the remaining nonvertical cases, define the slope $m \in \mathbb{F}_p$ as follows. If $P \neq Q$, set
\begin{align*}
m=\frac{y_2-y_1}{x_2-x_1}.
\end{align*}
If $P=Q$ and $y_1 \neq 0$, set
\begin{align*}
m=\frac{3x_1^2+a}{2y_1}.
\end{align*}
The denominators are nonzero by the exclusion of the vertical case and by $p \neq 2$. Define $x_3 \in \mathbb{F}_p$ and $y_3 \in \mathbb{F}_p$ by
\begin{align*}
x_3=m^2-x_1-x_2.
\end{align*}
\begin{align*}
y_3=m(x_1-x_3)-y_1.
\end{align*}
Since $m,x_1,x_2,y_1 \in \mathbb{F}_p$, we have $x_3,y_3 \in \mathbb{F}_p$. Define the affine line map $\ell: \mathbb{F}_p \to \mathbb{F}_p^2$ by
\begin{align*}
\ell(T)=(T,m(T-x_1)+y_1).
\end{align*}
Substituting this line into the Weierstrass equation gives the polynomial $G \in \mathbb{F}_p[T]$ defined by
\begin{align*}
G(T)=(m(T-x_1)+y_1)^2-(T^3+aT+b).
\end{align*}
The polynomial $G$ has degree $3$ and leading coefficient $-1$. In the secant case $P \neq Q$, the equalities $G(x_1)=G(x_2)=0$ follow from $P,Q \in E(\mathbb{F}_p)$. In the tangent case $P=Q$, the tangent slope formula gives $G(x_1)=0$ and $G'(x_1)=0$, so $x_1$ is counted as a double root. Since the coefficient of $T^2$ in $G$ is $m^2$, Vieta's relation gives the third root as
\begin{align*}
x_3=m^2-x_1-x_2,
\end{align*}
with $x_2=x_1$ in the tangent case. The corresponding third intersection point has ordinate $m(x_3-x_1)+y_1=-y_3$, and the sum is defined as its reflection across the $x$-axis:
\begin{align*}
P+Q=(x_3,y_3).
\end{align*}
Because the Weierstrass equation contains $Y$ only through $Y^2$, this reflected point also satisfies the equation. Therefore $P+Q \in E(\mathbb{F}_p)$.[/step]