We study cosmology of the Einstein-Yang-Mills theory in ten dimensions with a quartic term in the Yang-Mills field strength. We obtain analytically a class of cosmological solutions in which the extra dimensions are static and the scale factor of the four-dimensional Friedmann-Lemaitre-Robertson-Walker metric is an exponential function of time. This means that the model can explain inflation. Then we look for solutions that describe dynamical compactification of the extra dimensions. The effective cosmological constant $\lambda_1$ in the four-dimensional universe is determined from the gravitational coupling, ten-dimensional cosmological constant, gauge coupling and higher derivative coupling. By numerical integration, the solution with $\lambda_1=0$ is found to behave as a matter-dominated universe which asymptotically approaches flat space-time, while the solution with a non-vanishing $\lambda_1$ approaches de Sitter space-time in the asymptotic future.