Newton's second law: system with three blocks and a pulley

The latter is right.

If you take the forces acting on $M$ alone, you have - the normal force from $m2$. This is just $m2*a$. You also have the horizontal component of the force from the string on the pulley. This is (think about it) equal exactly to $m1*a$


The latter is right. Note, that "F is exerted on $m_1$" is no physical requirement. What you do require though, is that the force $F$ is applied on the whole system consisting of all three masses. Whatever happens internally; inside the system, pulleys, strings, mass blocks etc is nothing bother about as far as acceleration of the whole system is concerned. That is just total force applied divided by total mass.

As for your question, "which force accelerates $m_1$ horizontally with acceleration $a$?", it's the string (through tension), which is in turn pulled by the pulley. How? Note that the pulley applies a force on the string in the $\frac{1}{\sqrt{2}}(\hat{x}+\hat{y})$ direction (the direction normal to the surface of the pulley-string contact); The horizontal component of which causes the tension.