When the interaction between a molecular system and confined light modes in an optical or plasmonic cavity is strong enough to overcome the dissipative process, hybrid light-matter states (polaritons) become the fundamental excitations in the system. The mixing between the light and matter characters modifies the photophysical and photochemical properties. Notably, it was reported that these polaritons can be employed to control photochemical reactions, charge and energy transfer, and other processes. In addition, according to recent studies, vibrational strong coupling can be employed to resonantly enhance the thermally-activated chemical reactions. In this work, a theoretical model and an efficient numerical method for studying the dynamics of molecules strongly interacting with quantum light are developed based on nonadiabatic excited-state molecular dynamics. The methodology was employed to study the cis-trans photoisomerization of a realistic molecule in a cavity. Numerical simulations demonstrate that the photochemical reactions can be controlled by tuning the properties of the cavity. In the calculated example, the isomerization is suppressed when polaritonic states develop a local minimum on the lower polaritonic state. Moreover, the observed reduction of isomerization is tunable via the photon energy and light-molecule coupling strength. However, the fluctuation in the transition dipole screens the effect of light-matter, which makes it harder to tune the photochemical properties via the coupling strength. These insights suggest quantum control of photochemical reactions is possible by specially designed photonic or plasmonic cavities.