[proofplan]
We isolate the Hecke eigensystem of the rational normalized newform $f$ inside the Jacobian $J_0(N)$ by using the Eichler-Shimura construction for weight two newforms. Rationality of the Fourier coefficients forces the associated simple modular abelian variety to have dimension one, hence to be an elliptic curve over $\mathbb{Q}$. The Eichler-Shimura trace formula identifies the Frobenius trace of this elliptic quotient with $a_p(f)$ for every prime $p\nmid N$, and conductor-minimality for optimal newform quotients gives conductor exactly $N$. Uniqueness up to $\mathbb{Q}$-isogeny follows from multiplicity one for the Hecke eigensystem.
[/proofplan]
[step:Cut out the Hecke eigensystem attached to $f$ inside $J_0(N)$]
Let $\mathbb{T}$ denote the commutative Hecke algebra over $\mathbb{Z}$ generated by the Hecke operators $T_n$ acting on $S_2(\Gamma_0(N))$ and on $J_0(N)$. Define the character
\begin{align*}
\lambda_f:\mathbb{T}&\longrightarrow \mathbb{Q},\\
T_n&\longmapsto a_n(f),
\end{align*}
and define the ideal $I_f:=\ker(\lambda_f)\subset \mathbb{T}$.
Since $f$ is a normalized newform, the [multiplicity-one theorem for newforms](/page/Multiplicity%20One%20Theorem%20for%20Newforms) implies that the simultaneous Hecke eigenspace with eigenvalues $a_n(f)$ is one-dimensional over $\mathbb{C}$. Since every $a_n(f)$ lies in $\mathbb{Q}$, the image field of $\lambda_f$ is $\mathbb{Q}$. The [Eichler-Shimura construction](/page/Eichler-Shimura%20Construction) applied to the weight two newform $f$ therefore produces the abelian variety
\begin{align*}
A_f:=J_0(N)/I_fJ_0(N)
\end{align*}
over $\mathbb{Q}$ and a quotient morphism of abelian varieties over $\mathbb{Q}$
\begin{align*}
\pi_f:J_0(N)&\longrightarrow A_f.
\end{align*}
[guided]
The first task is to turn the analytic eigenform $f$ into an algebraic quotient of the modular Jacobian. Let $\mathbb{T}$ be the Hecke algebra generated by the operators $T_n$. Because $f$ is an eigenform, each $T_n$ acts on the line $\mathbb{C}f$ by the scalar $a_n(f)$, so we get a ring homomorphism
\begin{align*}
\lambda_f:\mathbb{T}&\longrightarrow \mathbb{Q},\\
T_n&\longmapsto a_n(f).
\end{align*}
The rationality hypothesis $a_n(f)\in\mathbb{Q}$ is used here: it says that the coefficient field of $f$ is exactly $\mathbb{Q}$ rather than a higher-degree number field.
Define $I_f:=\ker(\lambda_f)$. The [Eichler-Shimura construction](/page/Eichler-Shimura%20Construction) applies because $f$ is a normalized weight two newform for $\Gamma_0(N)$. Its conclusion is that the Hecke-stable ideal $I_f$ cuts out a quotient abelian variety
\begin{align*}
A_f:=J_0(N)/I_fJ_0(N)
\end{align*}
over $\mathbb{Q}$, together with the quotient morphism
\begin{align*}
\pi_f:J_0(N)&\longrightarrow A_f.
\end{align*}
The role of the [multiplicity-one theorem for newforms](/page/Multiplicity%20One%20Theorem%20for%20Newforms) is to ensure that the ideal $I_f$ really isolates the eigensystem of $f$: no second newform of the same level has all the same Hecke eigenvalues away from $N$.
[/guided]
[/step]
[step:Use rationality of the coefficient field to identify the quotient as an elliptic curve]
By the dimension formula in the [Eichler-Shimura construction](/page/Eichler-Shimura%20Construction), the dimension of $A_f$ equals the degree of the coefficient field $\mathbb{Q}(a_n(f):n\in\mathbb{N})$ over $\mathbb{Q}$. Since $a_n(f)\in\mathbb{Q}$ for every $n$, this field is $\mathbb{Q}$ and hence
\begin{align*}
\dim A_f=[\mathbb{Q}:\mathbb{Q}]=1.
\end{align*}
A one-dimensional abelian variety over $\mathbb{Q}$ is an elliptic curve over $\mathbb{Q}$ after choosing its identity element as origin. Set $E_f:=A_f$. Then
\begin{align*}
\pi_f:J_0(N)&\longrightarrow E_f
\end{align*}
is a quotient morphism over $\mathbb{Q}$.
[/step]
[step:Compare Frobenius traces with Hecke eigenvalues away from $N$]
Let $p$ be a prime with $p\nmid N$. Since $p$ is prime to the level, $J_0(N)$ has good reduction at $p$, the Hecke operator $T_p$ is defined on $J_0(N)$, and the quotient $E_f$ has good reduction at $p$. The [Eichler-Shimura relation](/page/Eichler-Shimura%20Relation) identifies the characteristic polynomial of geometric Frobenius acting on the $\ell$-adic Tate module of $A_f$ with
\begin{align*}
X^2-a_p(f)X+p
\end{align*}
for every auxiliary prime $\ell\neq p$. Therefore the Frobenius trace of $E_f=A_f$ at $p$ is $a_p(f)$, which is precisely
\begin{align*}
a_p(E_f)=a_p(f).
\end{align*}
[guided]
Now we check the asserted equality of traces. Fix a prime $p$ with $p\nmid N$. This hypothesis is exactly the good-prime condition needed for the Eichler-Shimura relation: the modular curve $X_0(N)$, its Jacobian $J_0(N)$, and the newform quotient all have good reduction at such $p$, and the Hecke operator $T_p$ is unramified at the level.
Choose an auxiliary prime $\ell\neq p$. The [Eichler-Shimura relation](/page/Eichler-Shimura%20Relation) says that, on the $\ell$-adic Tate module attached to the $f$-isotypic quotient, geometric Frobenius at $p$ has characteristic polynomial
\begin{align*}
X^2-a_p(f)X+p.
\end{align*}
For an elliptic curve $E/\mathbb{Q}$ with good reduction at $p$, the coefficient of $X$ in the Frobenius polynomial $X^2-a_p(E)X+p$ is by definition the negative of the Frobenius trace. Applying this to $E_f=A_f$ gives
\begin{align*}
a_p(E_f)=a_p(f).
\end{align*}
This proves the claimed trace equality for every prime away from the level.
[/guided]
[/step]
[step:Apply conductor minimality for the optimal newform quotient]
Because $f$ has exact level $N$, the [conductor theorem for optimal newform quotients](/page/Conductor%20Theorem%20for%20Optimal%20Newform%20Quotients) applies to the quotient $\pi_f:J_0(N)\to E_f$. Its hypotheses are satisfied: $f$ is a normalized newform, $E_f$ is the optimal quotient attached to the Hecke ideal $I_f$, and the level of $f$ is exactly $N$. The theorem gives
\begin{align*}
\operatorname{cond}(E_f)=N.
\end{align*}
[/step]
[step:Deduce uniqueness up to $\mathbb{Q}$-isogeny from the Hecke eigensystem]
Suppose $E/\mathbb{Q}$ is another elliptic curve quotient of $J_0(N)$ whose Frobenius traces satisfy $a_p(E)=a_p(f)$ for every prime $p\nmid N$. Then the associated Hecke eigensystem away from $N$ equals the eigensystem of $f$. By the [multiplicity-one theorem for newforms](/page/Multiplicity%20One%20Theorem%20for%20Newforms), this determines the same newform isogeny factor of $J_0(N)$. Equivalently, the corresponding quotients of $J_0(N)$ have the same simple abelian variety factor over $\mathbb{Q}$, so $E$ and $E_f$ are $\mathbb{Q}$-isogenous.
Thus the construction gives an elliptic curve $E_f/\mathbb{Q}$ of conductor $N$, a quotient map $\pi_f:J_0(N)\to E_f$, the equality $a_p(E_f)=a_p(f)$ for every $p\nmid N$, and uniqueness of $E_f$ up to $\mathbb{Q}$-isogeny.
[/step]