In this work, a mass-effective temperature-surface gravity relation (MTGR) is developed for main sequence stars in the range of 6400 K < $T_{rm eff}$ < 20000 K with log$g$ > 3.44. The MTGR allows the simple estimation of the masses of stars from their effective temperatures and surface gravities. It can be used for solar metallicity and can be rescaled for any metallicity within -1.00 < [Fe/H] < 0.7. The effect of alpha-enhanced compositions can also be considered with the help of correction terms. It is aimed to develop an MTGR that can estimate the masses of main-sequence stars from their atmospheric parameters. One advantage of an MTGR over the classical mass-luminosity relations is that its mass estimation is based on parameters that can be obtained by purely spectroscopic methods and, therefore, the interstellar extinction or reddening do not have to be known. The use of surface gravity ($g$) also relates an MTGR with stellar evolution and provides a more reliable mass estimation. A synthetical MTGR is obtained from theoretical isochrones using a Levenberg-Marquardt chi-square minimization algorithm. The validity of the MTGR is then checked by testing over 278 binary components with precise absolute masses. Very good agreement has been obtained between the absolute masses of 278 binary star components and their masses estimated from the MTGR. A mathematical expression is also given to calculate the propagated uncertainties of the MTGR masses. For the typical uncertainties in atmospheric parameters and metallicity, the typical uncertainties in the masses estimated from the MTGR mostly remain around 5-9%. The fact that this uncertainty level is only on average about three times as large as that of the absolute masses indicates that the MTGR is a very powerful tool for stellar mass estimation. A computer code, mtgr.pro, written in GDL/IDL is also provided for the relation.