Absorbing UV radiation, ozone protects life on Earth and plays a fundamental role in Earths temperature balance. The formation of ozone occurs through the ternary recombination reaction: O$_2$+O+M $rightarrow$ O$_3$+M, where M can be N$_2$, O$_2$ or Ar. Here, we developed a theoretical approach capable of modeling the formation of ozone molecules in ternary collisions, and applied it to the reaction with M=Ar because of extensive experimental data available. The rate coefficients for the direct formation of O$_3$ in ternary collisions O+O$_2$+Ar were computed for the first time as a function of collision energy, and thermally-averaged coefficients were derived for temperatures 5-900~K leading to a good agreement with available experimental data for temperatures 100-900~K. The present study shows that the formation of ozone in ternary collisions O+O$_2$+Ar at temperatures below 200~K proceeds through a formation of a temporary complex ArO$_2$, while at temperatures above 1000~K, the reaction proceeds mainly through a formation of long-lived vibrational resonances of O$_3^*$. At intermediate temperatures 200~K-1000~K, the process cannot be viewed as a two-step mechanism. In addition, it is found that the majority of O$_3$ molecules formed initially are weakly bound.