Why is a bijection that preserves connectedness on $\mathbf{R}$ must be monotone? In one of the remarks for this highly upvoted unanswered question: Does there exist a bijection of $\mathbb{R}^n$ with itself such that the forward map is connected but the inverse is not? , the author points out in the post that

a bijection that preserves connectedness on $\mathbf{R}$ must be monotone.

Why is this true?
I understand every single word in this statement, but I do not know how to prove it. To set up the notation,

Let $f:\mathbf{R}\to\mathbf{R}$ be a bijection such that for any connected subset $A$ in $\mathbf{R}$, the set $f(A)$ is also connected. How does one show that $f$ must be monotone?

To get a feeling for what could go wrong if $f$ is not monotone, I consider the simple case when $f(x)=x^2$. Obviously, $f(A)$ is connected for any connected set $A$ since $f$ is continuous; but it is not bijective. Other than this dumb example, I don't have any intuitions.
 A: Suppose that $f$ is not monotonic. Then there are numbers $a,b,c\in\Bbb R$ such that $a<b<c$ and that $f(b)$ is greater than both $f(a)$ and $f(c)$ or that $f(b)$ is smaller than both $f(a)$ and $f(c)$. Suppose that we are in the first case. You have $f(a)>f(c)$ or $f(a)<f(c)$ or $f(a)=f(c)$. In this last case, $f$ is not injective, and we're done. If $f(a)>f(c)$, then, $f([b,c])$ is not an interval, since it contains $f(b)$ and $f(c)$, but not $f(a)$. And if $f(a)<f(c)$, then, $f([a,b])$ is not an interval, since it contains $f(a)$ and $f(b)$, but not $f(c)$.
The other case is similar.
A: Here is a slightly different presentation of the José's nice answer; which I find easier to digest for myself.
Let us prove by contradiction and assume that $f$ is not monotonic. We first prove the following lemma.

Lemma. If $f:\mathbf{R}\to\mathbf{R}$ is not monotonic, then there exists real numbers $a,b,c$ with $a<b<c$ and
$$
(1)\quad f(b)> \max(f(a),f(c))\qquad \text{or}\qquad (2)\quad f(b)> \min(f(a),f(c))
$$

For case (1), there are three sub-cases:
(1.1) $f(a)>f(c)$. Then $f(c)<f(a)<f(b)$. Let $I=f([b,c])$. Since $f$ preserves connectedness, the set $I$ must be an interval and thus $[f(c),f(b)]\subset I$. It follows that $f(a)\in I$. But $f$ is bijective, so $a\in f^{-1}(I)=[b,c]$, which contradicts the assumption that $a<b<c$.
(1.2) $f(a)<f(c)$. Then $f(a)<f(c)<f(b)$. We can then argue similarly as in (1.1) and consider $I=f([a,b])$. We can then get the contradiction that $c\in[a,b]$.
(1.3) $f(a)=f(c)$. This is impossible since $f$ is bijective and particularly injective.
One can discuss (2) similarly.

Proof of the lemma. If $f$ is monotonic, then for any $a,b,c$ with $a<b<c$ one must have

*

*either $f(b)\in[f(a),f(c)]$, if $f$ is increasing;

*or $f(b)\in[f(c),f(a)]$, if $f$ is decreasing.

(1) and (2) are nothing but the negation of these two cases.
