This can be generalized a bit. it happens that every positive integer $n$ is the sum of four squares, $n = A^2 + B^2 + C^2 + D^2.$ The we get, from manipulating quaternions with integer coefficients,
$$ n^2 = (A^2 + B^2 - C^2 - D^2)^2 + (-2AC +2BD)^2 + (-2AD-2BC)^2 $$
I rewrote the version I had to agree with the Euler four square formula in the beginning of the Wikipedia article, with substitutions
$$ a_1 = A, b_1 = A, a_2 = B, b_2 = B, a_3 = C, b_3 = -C, a_4 = D, b_4 = -D $$
so that the second of the four terms cancels out to zero. I think this formula is associated with Lebesgue, let me see if i can find that. It plays a big part in Jones and Pall (1939).
Well, I requested the 1951 number theory book by Trygve Nagell, evidently it is one source of the idea that Lebesgue was involved.
Hmmm; Euler's four square identity 1748, then Lagrange four square theorem 1770, then Hamilton invents quaternions 1843. The (Henri) Lebesgue we know about lived 1875-1941.
NO, on page 266 of Volume II of Dickson's History of the Theory of Numbers, we find the statement that one V. A. Lebesgue, in 1874, proved the the square of a sum of three squares is again the sum of three squares in a nontrivial manner, as
$$ (\alpha^2 + \beta^2 + \gamma^2)^2 = (\alpha^2 + \beta^2 - \gamma^2)^2 + (2\alpha \gamma)^2 + (2 \beta \gamma)^2. $$
This is formula (4) on that page.
Who is V. A. Lebesgue?
Victor-Amédée Lebesgue, sometimes written Le Besgue, (2 October 1791,
Grandvilliers (Oise) – 10 June 1875, Bordeaux (Gironde)) was a
mathematician working on number theory.
Evidently the precise reference is V. A. Lebesgue, Sur un identite qui conduit a toutes les solutions
de l'equation $t^2 = x^2 + y^2 + z^2,$ Compte Rendus de l`Academie des Sciences de Paris 66 (1868), 396-398.
A 1962 article by Spira gives a short elementary proof that all primitive solutions can be found using this formula. He says that the first correct proof of such completeness was Dickson in 1920, with another by Skolem in 1941. Spira adapts the proof of Skolem to give an algorithm for finding at least one set $A,B,C,D$ from a given primitive Pythagorean quadruple.