Solution (source code)

= Solution

Add new constants $\bar c$ and consider
$$
\operatorname{ElDiag}(M)\cup\{\varphi(\bar c):\varphi\in p\}.
$$
Every finite subset is satisfiable because $p$ is consistent over $M$. By the <compactness theorem> it has a model $N'$. The constants naming $M$ give an elementary embedding $M\to N'$, and $\bar c^{N'}$ realizes $p$. Replacing $N'$ by an isomorphic copy containing $M$ gives the required <realization of a type in an elementary extension>.