How to translate field equation into Lagrangian density? I'm learning about particle physics, and I was troubled by how one could write the Lagrangian density out of the field equation. 
Klein-Gordon equation $$(\partial_\mu\partial^\mu +m^2)\phi(t,\vec x)=0$$ translated into $${\cal L} =\frac{1}{2} (\partial^\mu \phi \partial_\mu\phi -m^2\phi^2),$$ 
and the Dirac equation $$(i\gamma^\mu \partial_\mu-m)\Psi=0 $$ translated into $${\cal L}=\bar\Psi(i\gamma^\mu\partial_\mu-m)\psi.$$
Could you explain to me that how, in general, one could translate the field equation into Lagrangian density?
 A: Better than guessing the Lagrangian from the Equations of Motion, it is much more appealing to construct the Lagrangian from first principles.
Let me give you an example. If you want to describe the dynamics of a real spin 0 particle, you must first embed it into a field, namely the field $\phi$ you wrote, which is a Lorentz scalar. Because the Lagrangian (density) is Lorentz invariant, it contains all possible Lorentz invariant combinations of $\phi$ and derivatives of $\phi$. In order to obtain a linear differential Eq. we include only quadratic terms in $\phi$ in the Lagrangian; it is quite straightforward to see that$$\mathscr{L}=c_1 \partial_\mu\phi\partial_\mu\phi+c_2\phi^2$$is the only possibility, since $\phi$ does not possess any Lorentz structure. The coefficients are determined based on physical grounds and appropriate normalization.
For the Dirac Eq. this procedure is a bit more subtle, since the field $\Psi$ has a non-trivial representation of the Lorentz group, but the philosophy is the same. You can find this explicit construction in Schwartz's book, "Quantum Field Theory and the Standard Model", in chapter 10. Just to conclude, this procedure works for any spin (=Lorentz representation) you may desire; another good example you can find in Schwartz's book is the spin 2 case.
