Here I’m assuming some prior knowledge of QFT and the basics of differential geometry, and I will try from those basics to motivate the construction of the well-known Yang-Mills gauge Lagrangian :

What do we require of a term going into the Lagrangian? Simply that it be of **dimension** $n$, **Lorentz invariant** and **gauge invariant**. Let us then consider the oriented manifold $(\mathbb{R}^n,\eta,\epsilon)$, equiped with a Lie group G and its corresponding Lie algebra $\mathfrak{g}$. Let $A$, the *gauge potential*, be a $\mathfrak{g}$-valued 1-form : $A=A_a\mathrm{dx}^a=A_a^{\,\alpha}T_\alpha\mathrm{dx}^a$; where $T_\alpha\in\mathfrak{g}$ and satisfies $[T_\alpha,T_\beta]=c_{\alpha\beta\gamma}T_\gamma$.

What other objects can we build from $A$? Well, we can start by defining the covariant derivative

with which we can build a 2-form $D\omega=\mathrm{d}\omega+A\wedge\omega$ from any 1-form $\omega$. In particular :

where $F$ is the *gauge field strength tensor* we’re ultimately after. These two objects generate equivalence classes under gauge transformations :

where $g\in G$. Wedging the 2-form with its ($n$-2)-form Hodge dual $\star F$, we produce an $n$-form $F\wedge\star F$ : a potential candidate for our Lagrangian. As an $n$-form, it is a pseudoscalar form and thus a proper Lorentz invariant. We have therefore already checked two boxes out of three; there remains only to decide whether it is also gauge invariant :

where we used the linearity of the wedge operator. Our pseudoscalar form is therefore not gauge invariant (as it transforms in the adjoint representation), but taking the trace removes this gauge dependence (by cyclicity). Thus the only Lorentz- and gauge- invariant $n$-form built from gauge fields and that can enter the Lagrangian is $\mathrm{Tr}\left(F\wedge\star F\right)$. The Yang-Mills Lagrangian and equations then read :

Let’s now reduce the problem to $n=4$ dimensions and consider the special case $G=SU(2)$, i.e. when we have $c_{\alpha\beta\gamma}=\epsilon_{\alpha\beta\gamma}$ and $\mathrm{Tr}(T_\alpha T_\beta)=-\frac{1}{2}\delta_{\alpha\beta}$. Then :