Consider the scenario where a particle of mass $M$ decays into two lighter particles of mass $m_1$ and $m_2.$ In the center of mass frame (i.e. $\mathbf{p}_1$ and $\mathbf{p}_2$, the momenta of the products, sum to zero) the equations for the magnitude of the momenta of each of the particles is as follows:
$$p=\left|\mathbf{p}_1\right|=\left|\mathbf{p}_2\right|=\frac{\left[\left(M^2-(m_1+m_2)^2\right)\left(M^2-(m_1-m_2)^2\right)\right]^{1/2}}{2M}\,\,\,[\textrm{see ref., Eq. (45.16)}]$$
However, when I try to calculate it using basic principles I arrive at something different. Here is my attempt:
In the center of mass frame before the decay, the total energy of the system was $E^2=M^2c^4$. After the decay, the total energy was given by
$$\begin{align*}E'^2&=p^2c^2+m_1^2c^4+p^2c^2+m_2^2c^4\\ &=2p^2c^2+(m_1^2+m_2^2)c^4\end{align*}$$
Because energy is assumed to be conserved (reference frame is the same), this means that
$$\begin{align}M^2c^4&=2p^2c^2+(m_1^2+m_2^2)c^4\\ \implies p^2&=\frac{c^2}{2}\left(M^2-(m_1^2+m_2^2)\right)\\ p&=\frac{c}{\sqrt{2}}\sqrt{M^2-(m_1^2+m_2^2)}\end{align}$$
My answer seems completely different from what I'm supposed to get, so I'm sure my approach is horribly invalid. I don't know how though. Could you please point out my errors, and possibly guide me in the right direction?
[ref] http://pdg.lbl.gov/2013/reviews/rpp2013-rev-kinematics.pdf