suppose $f$ has at least one discontinuity point $x$, i.e.
$$
(\exists\epsilon>0)(\forall\delta>0)(\exists x'\in(x-\delta,x+\delta))\quad|f(x')-f(x)|\ge\epsilon\text;
$$
in particular, for each $n\in\mathbb N$ we can choose $x_n$ so that
$$
|x_n-x|<\frac1{n+1}\quad\&\quad|f(x_n)-f(x)|\ge\epsilon\text;
$$
choose
$$
r_+\in(f(x),f(x)+\epsilon)\cap\mathbb Q
\\ r_-\in(f(x)-\epsilon,f(x))\cap\mathbb Q
$$
then, by the IVP, there exists some $y_n$ between $x_n$ and $x$ such that
$$
f(y_n)=r_+\quad\text{or}\quad f(y_n)=r_-
$$
(depending whether $f(x_n)>f(x)$ or $f(x_n)<f(x)$); in particular,
$$
y_n\rightarrow x\text;
$$
suppose the '$+$' case occurs infinitely often (otherwise consider the '$-$' case): the corresponding subsequence lies in $f^{-1}(r_+)$ (closed by assumption), thus
$$
f(x)=r_+\text,
$$
in contradiction to the choice of $r_+$. this shows that no discontinuity point exists, i.e. $f$ is continuous.
EDIT my previous attempt (below) was wrong, disregard
consider the preimage of $I\cap\mathbb Q$, where $I=[a,b]$, and show that its closure is the preimage of $I$.
for any $x\in \overline {f^{-1}(I\cap\mathbb Q)}$ take a sequence $\{x_n\}$ in $f^{-1}(I\cap\mathbb Q)$ converging to $x$. then either infinitely many $x_n$'s lie in one of the $f^{-1}(r)$'s, or each $f^{-1}(r)$ only contains finitely many $x_n$'s (so the sequence intersects infinitely many $f^{-1}(r)$'s).
in the first case, the subsequence lying in $f^{-1}(r)$ (closed) converges in this set, so $x\in f^{-1}(r)$.
in the second case, construct a sequence $\{r_m\}$ and show $$f(x)=\lim_{m\rightarrow\infty}r_m$$
Also, suppose, we now proved the closure of pre-image is the the interval $[a,b]$, why does that mean we are done?
– Lost1 Apr 10 '13 at 10:22