The Klein-Gordon equation is a relativistic wave equation that describes the behavior of a scalar field. It is a second-order partial differential equation, which means that it involves both the field and its spatial derivatives. The equation is given by:

$\left( \Box + m^2 \right) \phi(x) = 0$

where $\Box = \frac{1}{\sqrt{-g}}\partial_\mu \left(\sqrt{-g}g^{\mu\nu}\partial_\nu\right)$ is the d’Alembert operator, $m$ is the mass of the scalar field, and $g_{\mu\nu}$ is the metric tensor.

The Klein-Gordon equation can be derived by starting with the action for a free scalar field, given by:

$S = \int d^4x \sqrt{-g} \left[ \frac{1}{2}g^{\mu\nu}\partial_\mu \phi \partial_\nu \phi – \frac{1}{2}m^2\phi^2 \right]$

The equation of motion can be obtained by taking the functional derivative of the action with respect to the scalar field, and setting it equal to zero:

$\frac{\delta S}{\delta \phi} = 0$

After performing some algebraic manipulation and applying the chain rule for functional derivatives, we get the Klein-Gordon equation.

**Complete Derivation**

Starting with the action for a free scalar field, given by:

$S = \int d^4x \sqrt{-g} \left[ \frac{1}{2}g^{\mu\nu}\partial_\mu \phi \partial_\nu \phi – \frac{1}{2}m^2\phi^2 \right]$

where $g$ is the determinant of the metric tensor $g_{\mu\nu}$, $\phi$ is the scalar field and $m$ is the mass of the scalar field.

The equation of motion can be obtained by taking the functional derivative of the action with respect to the scalar field, and setting it equal to zero:

$\frac{\delta S}{\delta \phi} = 0$

Let’s find the functional derivative of the action.

$\frac{\delta S}{\delta \phi} = \int d^4x \sqrt{-g} \left[ g^{\mu\nu}\partial_\mu \phi \partial_\nu – m^2\phi \right]\frac{\delta \phi}{\delta \phi}$

Now we can use the chain rule for functional derivatives

$\frac{\delta S}{\delta \phi} = \int d^4x \sqrt{-g} \left[ g^{\mu\nu}\partial_\mu \frac{\delta \phi}{\delta \phi}\partial_\nu \phi – m^2\phi \frac{\delta \phi}{\delta \phi} \right]$

Now, we can simplify by noticing that $\frac{\delta \phi}{\delta \phi} = 1$, and we obtain

$\frac{\delta S}{\delta \phi} = \int d^4x \sqrt{-g} \left[ g^{\mu\nu}\partial_\mu \partial_\nu \phi – m^2\phi \right] = 0$

We can make use of the D’Alembert operator, $\Box = \frac{1}{\sqrt{-g}}\partial_\mu \left(\sqrt{-g}g^{\mu\nu}\partial_\nu\right)$ to obtain the Klein-Gordon equation:

$\Box \phi + m^2 \phi = 0$

This equation is the Klein-Gordon equation, which describes the behavior of a scalar field in a relativistic setting.

Note that the Klein-Gordon equation is not a unique equation for the description of the scalar field because, for example, the Proca equation or the Fierz-Pauli equation can also be used.