Emilio Pisanty and Eckhard Giere have already given discontinuous, piecewise constant counterexamples in their answers. Here we provide for-the-fun-of-it a smooth infinitely-many-times-differentiable counterexample $f\in C^{\infty}(\mathbb{R})$ of a square integrable function $f:\mathbb{R} \to [0,1]$ that does not satisfy $\lim\limits_{|x|\to \infty}f(x)=0$. Our counterexample is
$$\begin{align}
f(x)~:=~& e^{- g(x)} ~\in ~]0,1], \cr
g(x)~:=~&x^4 \sin^2 x~\in ~[0,\infty[. \end{align}\tag{1} $$
Intuitive idea: If we imagine $x$ as a time variable, then the function $f$ returns periodically to its maximum value
$$ f(x) ~=~1
\quad\Leftrightarrow\quad
g(x) ~=~0
\quad\Leftrightarrow\quad
\frac{x}{\pi}~\in~ \mathbb{Z} ,\tag{2}$$
but spends most of its time close to the $x$-axis in order to be square integrable.
Proof: We leave a detailed, rigorous epsilon-delta mathematical proof to the reader, but a sketched heuristic proof goes like this. For each very large integer $|n|\gg 1$, define a shifted variable
$$ y~:=~x-\pi n.\tag{3}$$
For the fixed integer $n\in\mathbb{Z}$, always assume from now on that the $y$-variable belongs to the interval
$$ |y|~\leq~ \frac{\pi}{2}.\tag{4}$$
For $|y|\ll\frac{\pi}{2}$ very small, we may approximate $g(x) \approx (\pi n)^4y^2$, so that in the interval $(4)$, we have
$$ g(x)~\lesssim~ \pi^4 |n|
\quad \Leftrightarrow\quad
|y| ~\lesssim~ |n|^{-\frac{3}{2}}.\tag{5}$$
Thus we may form a square-integrable majorant function $h\geq f$ (outside a compact region on the $x$-axis) by defining
$$ h(x)~:=~\left\{\begin{array}{lcl} 1 &{\rm for}& |y| ~\lesssim~ |n|^{-\frac{3}{2}}, \cr
e^{-\pi^4 |n|}&{\rm for}& |n|^{-\frac{3}{2}}~\lesssim~ |y| ~\leq~ \frac{\pi}{2}, \end{array} \right. \qquad |n|\gg 1. \tag{6}$$
The function $h\in {\cal L}^2(\mathbb{R})$ is square integrable on the whole $x$-axis, since
$$ \sum_{n\neq 0} |n|^{-\frac{3}{2}} ~<~ \infty\tag{7}$$
and
$$ \pi \sum_{n\in\mathbb{Z}}e^{-2\pi^4 |n|}~<~\infty\tag{8}$$
are convergent series.