We give a counterexample.
Let $R$ be the noncommutative ring of $2\times 2$ matrices with real coefficients.
Consider the following matrices $A, B$ in $R$.
\[A=\begin{bmatrix}
0 & 1\\
0& 0
\end{bmatrix} \text{ and } B=\begin{bmatrix}
0 & 0\\
1& 0
\end{bmatrix}.\]
Direct computation shows that $A^2$ and $B^2$ are the zero matrix, hence $A, B$ are nilpotent elements.

However, the sum $A+B=\begin{bmatrix}
0 & 1\\
1& 0
\end{bmatrix}$ is not nilpotent as we have
\begin{align*}
\begin{bmatrix}
0 & 1\\
1& 0
\end{bmatrix}^n
=\begin{cases} \begin{bmatrix}
0 & 1\\
1& 0
\end{bmatrix} & \text{if $n$ is odd}\\[10pt]
\begin{bmatrix}
1 & 0\\
0& 1
\end{bmatrix} & \text{ if $n$ is even}.
\end{cases}
\end{align*}
Hence the set of nilpotent elements in $R$ is not an ideal as it is not even an additive abelian group.

Comment.

If a ring $R$ is commutative, then it is true that the set of nilpotent elements form an ideal, which is called the nilradical of $R$.

Nilpotent Element a in a Ring and Unit Element $1-ab$
Let $R$ be a commutative ring with $1 \neq 0$.
An element $a\in R$ is called nilpotent if $a^n=0$ for some positive integer $n$.
Then prove that if $a$ is a nilpotent element of $R$, then $1-ab$ is a unit for all $b \in R$.
We give two proofs.
Proof 1.
Since $a$ […]

A Ring Has Infinitely Many Nilpotent Elements if $ab=1$ and $ba \neq 1$
Let $R$ be a ring with $1$.
Suppose that $a, b$ are elements in $R$ such that
\[ab=1 \text{ and } ba\neq 1.\]
(a) Prove that $1-ba$ is idempotent.
(b) Prove that $b^n(1-ba)$ is nilpotent for each positive integer $n$.
(c) Prove that the ring $R$ has infinitely many […]

Boolean Rings Do Not Have Nonzero Nilpotent Elements
Let $R$ be a commutative ring with $1$ such that every element $x$ in $R$ is idempotent, that is, $x^2=x$. (Such a ring is called a Boolean ring.)
(a) Prove that $x^n=x$ for any positive integer $n$.
(b) Prove that $R$ does not have a nonzero nilpotent […]

If the Quotient Ring is a Field, then the Ideal is Maximal
Let $R$ be a ring with unit $1\neq 0$.
Prove that if $M$ is an ideal of $R$ such that $R/M$ is a field, then $M$ is a maximal ideal of $R$.
(Do not assume that the ring $R$ is commutative.)
Proof.
Let $I$ be an ideal of $R$ such that
\[M \subset I \subset […]

Characteristic of an Integral Domain is 0 or a Prime Number
Let $R$ be a commutative ring with $1$. Show that if $R$ is an integral domain, then the characteristic of $R$ is either $0$ or a prime number $p$.
Definition of the characteristic of a ring.
The characteristic of a commutative ring $R$ with $1$ is defined as […]

Equivalent Conditions For a Prime Ideal in a Commutative Ring
Let $R$ be a commutative ring and let $P$ be an ideal of $R$. Prove that the following statements are equivalent:
(a) The ideal $P$ is a prime ideal.
(b) For any two ideals $I$ and $J$, if $IJ \subset P$ then we have either $I \subset P$ or $J \subset P$.
Proof. […]

Prime Ideal is Irreducible in a Commutative Ring
Let $R$ be a commutative ring. An ideal $I$ of $R$ is said to be irreducible if it cannot be written as an intersection of two ideals of $R$ which are strictly larger than $I$.
Prove that if $\frakp$ is a prime ideal of the commutative ring $R$, then $\frakp$ is […]

A Ring is Commutative if Whenever $ab=ca$, then $b=c$
Let $R$ be a ring and assume that whenever $ab=ca$ for some elements $a, b, c\in R$, we have $b=c$.
Then prove that $R$ is a commutative ring.
Proof.
Let $x, y$ be arbitrary elements in $R$. We want to show that $xy=yx$.
Consider the […]