The answer is yes. Here's one way to prove it. (There might be a slicker way, but this seems to work.)
Assume $G$ is connected and closed. Let $a\in\mathbb R$ be arbitrary, and let $\epsilon>0$ be given. Because $(a,f(a)-\epsilon)\notin G$, the fact that the complement of $G$ is open implies that there is a product neighborhood of the form $(a-\delta,a+\delta)\times (f(a)-\epsilon-c, f(a)-\epsilon+c)$ contained in the complement of $G$. This means that $|x-a|<\delta$ implies that one of the following two inequalities holds:
- $f(x)\ge f(a)-\epsilon+c>f(a)-\epsilon$, or
- $f(x)\le f(a)-\epsilon-c$.
If there is any $x\in (a-\delta,a+\delta)$ so that the second inequality holds, say $f(b)\le f(a)-\epsilon-c$ (without loss of generality, we may assume $b\lt a$), then the graph of $f$ does not intersect the following set:
$$\\{(b,y): y\ge f(a)-\epsilon \\}\cup \\{(x,f(a)-\epsilon): b\le x \le a\\} \cup \\{(a,y): y\le f(a)-\epsilon\\}.$$
(See the diagram below.) This broken line disconnects $G$, contradicting the assumption that $G$ is connected. Therefore inequality (1) holds when $|x-a|<\delta$.
A similar argument shows that $f(x)\lt f(a)+\epsilon$ when $|x-a|<\delta$.
Putting these together, we conclude that $|x-a|<\delta$ implies $|f(x)-f(a)|<\epsilon$, so $f$ is continuous at $a$.
