Recent experimental advances in atomically thin transition metal dichalcogenide (TMD) metals have unveiled a range of interesting phenomena including the coexistence of charge-density-wave (CDW) order and superconductivity down to the monolayer limit. The atomic thickness of two-dimensional (2D) TMD metals also opens up the possibility for control of these electronic phase transitions by electrostatic gating. Here we demonstrate reversible tuning of superconductivity and CDW order in model 2D TMD metal NbSe$_2$ by an ionic liquid gate. A variation up to ~ 50% in the superconducting transition temperature has been observed, accompanied by a correlated evolution of the CDW order. We find that the doping dependence of the superconducting and CDW phase transition in 2D NbSe$_2$ can be understood by a varying electron-phonon coupling strength induced by the gate-modulated carrier density and the electronic density of states near the Fermi surface.