Accurate estimation of the locations and extents of neural sources from electroencephalography and magnetoencephalography (E/MEG) is challenging, especially for deep and highly correlated neural activities. In this study, we proposed a new fully data-driven source imaging method, source imaging based on spatio-temporal basis function (SI-STBF), which is built upon a Bayesian framework, to address this issue. The SI-STBF is based on the factorization of a source matrix as a product of a sparse coding matrix and a temporal basis function (TBF) matrix, which includes a few TBFs. The prior of the TBF is set in the empirical Bayesian manner. Similarly, for the spatial constraint, the SI-STBF assumes the prior covariance of the coding matrix as a weighted sum of several spatial covariance components. Both the TBFs and the coding matrix are learned from E/MEG simultaneously through variational Bayesian inference. To enable inference on high-resolution source space, we derived a scalable algorithm using convex analysis. The performance of the SI-STBF was assessed using both simulated and experimental E/MEG recordings. Compared with L2-norm constrained methods, the SI-STBF is superior in reconstructing extended sources with less spatial diffusion and less localization error. By virtue of the spatio-temporal factorization of source matrix, the SI-STBF also produces more accurate estimations than spatial-only constraint method for high correlated and deep sources.