Using first-principles calculations, we identify the origin of the observed charge density wave (CDW) formation in a layered kagome metal CsV$_3$Sb$_5$. It is revealed that the structural distortion of kagome lattice forming the trimeric and hexameric V atoms is accompanied by the stabilization of quasimolecular states, which gives rise to the opening of CDW gaps for the V-derived multibands lying around the Fermi level. This Jahn-Teller-like instability having the local lattice distortion and its derived quasimolecular states is a driving force of the CDW order. Specifically, the saddle points of multiple Dirac bands near the Fermi level, located at the $M$ point, are hybridized to disappear along the $k_z$ direction, therefore not supporting the widely accepted Peierls-like electronic instability due to Fermi surface nesting. It is further demonstrated that applied hydrostatic pressure significantly reduces the interlayer spacing to destabilize the quasimolecular states, leading to a disappearance of the CDW phase at a pressure of ${sim}$2 GPa. The presently proposed underlying mechanism of the CDW order in CsV$_3$Sb$_5$ can also be applicable to other isostructural kagome lattices such as KV$_3$Sb$_5$ and RbV$_3$Sb$_5$.