[proofplan]
We first realize $P$ as a direct summand of a finite free module by choosing finitely many generators and using projectivity to split the resulting surjection. This embeds $P$ into a free module $R^m$, and hence allows us to prove that $P$ is torsion-free by checking coordinates in $R^m$. Finally, we invoke the [structure theorem for finitely generated modules over a principal ideal domain](/theorems/3233): a finitely generated torsion-free module over a [principal ideal domain](/page/Principal%20Ideal%20Domain) is free.
[/proofplan]
[step:Split a finite free presentation of $P$]
If $P = 0$, then $P$ is the free $R$-module of rank $0$, so assume $P \neq 0$. Since $P$ is finitely generated, choose $m \in \mathbb{N}$ and elements $p_1,\dots,p_m \in P$ generating $P$ as an $R$-module. Let $e_1,\dots,e_m$ denote the standard basis of the free $R$-module $R^m$. Define the $R$-module homomorphism
\begin{align*}
\pi: R^m &\to P \\
\sum_{i=1}^m a_i e_i &\mapsto \sum_{i=1}^m a_i p_i .
\end{align*}
Because $p_1,\dots,p_m$ generate $P$, the map $\pi$ is surjective.
Since $P$ is projective, the surjective $R$-module homomorphism $\pi: R^m \to P$ admits an $R$-linear section. Thus there exists an $R$-module homomorphism
\begin{align*}
s: P &\to R^m
\end{align*}
such that $\pi \circ s = \operatorname{id}_P$. In particular, $s$ is injective: if $s(p)=0$ for some $p \in P$, then
\begin{align*}
p = \operatorname{id}_P(p) = (\pi \circ s)(p) = \pi(0) = 0.
\end{align*}
Therefore $P$ is isomorphic to the submodule $s(P) \subset R^m$.
[/step]
[step:Show that $P$ is torsion-free by embedding it in $R^m$]
We prove that $P$ is torsion-free as an $R$-module. Let $a \in R$ and $p \in P$ satisfy $a \neq 0$ and $ap = 0$. Applying the $R$-[linear map](/page/Linear%20Map) $s: P \to R^m$ gives
\begin{align*}
a\,s(p) = s(ap) = s(0) = 0.
\end{align*}
Write
\begin{align*}
s(p) = (r_1,\dots,r_m)
\end{align*}
with $r_1,\dots,r_m \in R$. Then $a\,s(p)=0$ in $R^m$ means
\begin{align*}
ar_i = 0
\end{align*}
for every $i \in \{1,\dots,m\}$. Since $R$ is a principal ideal domain, it is an integral domain. Because $a \neq 0$, each equality $ar_i=0$ forces $r_i=0$. Hence $s(p)=0$, and the injectivity of $s$ gives $p=0$.
Thus, whenever $a \in R \setminus \{0\}$ and $p \in P$ satisfy $ap=0$, we have $p=0$. Therefore $P$ is torsion-free.
[/step]
[step:Apply the structure theorem for finitely generated modules over a principal ideal domain]
The module $P$ is finitely generated by hypothesis and torsion-free by the previous step. By the structure theorem for finitely generated modules over a principal ideal domain, specifically the consequence that every finitely generated torsion-free module over a principal ideal domain is free (citing a result not yet in the wiki: Structure Theorem for Finitely Generated Modules over a Principal Ideal Domain), it follows that $P$ is a free $R$-module.
This proves that every finitely generated projective module over a principal ideal domain is free.
[/step]