TITLE: Continuous composition with one discontinuous function
QUESTION [6 upvotes]: Suppose $X$ is some connected topological space, $I$ is an interval and $Y$ is some topological space. Let $g: X\to I$ be a continuous and surjective function. Let $f$ be a function $I \to Y$. If $f \circ g$ is continuous, must $f$ be continuous? 
To prove this is suffices to prove that if $x \in I$ and $x_n$ converges to $x$ from either below or above then $f(x_n)$ converges to $f(x)$. Let us assume wlog that $x_n \geq x$ for all $n$. It would be enough to find $y$ and $y_n$ such that $g(y_n)=x_n$, $g(y)=x$ and $y_n \to y$. 
There is some $y \in X$ such that $f(y)=x$. In addition we can pick $y$ so that every open set $ U \ni y$ contains a $z$ with $g(z)>x$. (Follows from connectedness.) If $X$ were first-countable I think this would imply the existence of the desired sequence $y_n$. But I cannot see how to conclude this in general.

REPLY [5 votes]: $f$ need not be continuous.
Let $X = Y$ be the topologist's sine curve, i.e.
$$X = Y = \{(x, \sin(1/x)) : 0 < x \le 1\} \cup (0,0) \subset \mathbb{R}^2$$
with the Euclidean topology.  It is well known and easy to check that $X$ is connected.  Take $I = [0,1]$ and define $g : X \to I$ by $g(x,y) = x$; then $g$ is a continuous bijection.  Let $f = g^{-1}$, i.e.
$$f(x) = \begin{cases} (x, \sin(1/x)), & 0 < x \le 1 \\ (0,0), & x=0. \end{cases}$$
Then $f \circ g$ is the identity map on $X$ which is continuous, but $f$ is not continuous.
An example with $I$ an open interval can be constructed similarly (for instance, take $I=(-1,1)$ and just reflect this picture about the $y$ axis).