TITLE: what is the relation between quaternions and imaginary numbers?
QUESTION [20 upvotes]: I understand the idea behind complex and imaginary numbers. I am trying to understand quaternions. 
What is the relation between imaginary (or complex) numbers, and quaternions?

REPLY [23 votes]: EDITED
Let's start with the real line $\mathbb{R}$ constituted of real numbers $t$. This field is not algebraically closed from the absence of a real solution to the simple polynomial equation : $$\tag{1} X^2=-1$$ 
A solution of $(1)$ named $\,\mathbf{i}\,$ was invented and supposed belonging to the (imaginary) orthogonal to the real line at $0$. The 'numbers' $\;t+x\,\mathbf{i}\;$ with $\,t,x\,$ real constituting the field $\,\mathbb{C}$. This field is algebraically closed and nothing further needed to be added at this point. 
But Hamilton wanted to get out of the plane and imagined another independent solution $\,\mathbf{j}\,$ of $(1)$ belonging to the orthogonal to the real and imaginary lines at $0$.
Playing with these new 'extended numbers' $\;t+x\,\mathbf{i}+y\,\mathbf{j}\;$ filling the 3D space he got into trouble with multiplication since the product of two 'extended numbers' contained the products $\,\mathbf{i}\,\mathbf{j}\,$ and $\,\mathbf{j}\,\mathbf{i}$.
Suppose that $\,\mathbf{i}\,\mathbf{j}\,$ belongs to the 3D space : this means that $\;\mathbf{i}\,\mathbf{j}=a+b\,\mathbf{i}+c\,\mathbf{j}\;$ but if we multiply this (at the left) by $\mathbf{i}\,$, replace $\mathbf{i}\,\mathbf{j}\,$ by the initial expression and simplify everything then we get $\mathbf{j}$ as $\;\mathbf{j}=\alpha +\beta\,\mathbf{i}\;$ : the 3D space collapsed back to the initial complex plane!
From the distributivity and associativity of the product we can't thus have two independent $\mathbf{i}\,$ and $\mathbf{j}\,$ without their product $\;\mathbf{k}:=\mathbf{i}\,\mathbf{j}\,$ being independent too : the 4D space generated by $\,(1,\,\mathbf{i},\,\mathbf{j},\,\mathbf{k})\,$ is mandatory!
And what about $\,\mathbf{j}\,\mathbf{i}$?
If we suppose that $\,\mathbf{i}\,\mathbf{j}=\mathbf{j}\,\mathbf{i}\,$ then everything will remain commutative with $\,\mathbf{k}^2=1\,$ and we obtain what was named tessarines by James Cockle and later bicomplex numbers that were further generalized to multicomplex numbers ($\,\mathbf{k}$ itself defining a split-complex number).
But before all this Hamilton noticed that $\,\left(x\,\mathbf{i}+y\,\mathbf{j}\right)^2=xy\;(\mathbf{i}\,\mathbf{j}+\mathbf{j}\,\mathbf{i})-(x^2+y^2)\,$ so that abandoning commutativity and supposing that $\,\mathbf{k}=\mathbf{i}\,\mathbf{j}=-\mathbf{j}\,\mathbf{i}\;$ he could rewrite not only $\,\left(x\,\mathbf{i}+y\,\mathbf{j}\right)^2=-(x^2+y^2)\,$ but also $\,\mathbf{k}^2=-1\,$ and $\,\left(x\,\mathbf{i}+y\,\mathbf{j}+z\,\mathbf{k}\right)^2=-(x^2+y^2+z^2)$.
The 3D space he wished was thus generated by $\,(\mathbf{i},\,\mathbf{j},\,\mathbf{k})\,$ instead of $\,(1,\,\mathbf{i},\,\mathbf{j})\,$ and he gained further an interesting fourth dimension! He was proud enough of his discovery to carve his very nice result into the stone of Brougham Bridge :
$$\boxed{\displaystyle\mathbf{i}^2=\mathbf{j}^2=\mathbf{k}^2=\mathbf{i}\mathbf{j}\mathbf{k}=-1}$$