In this work, we present a new method to estimate cosmological parameters accurately based on the artificial neural network (ANN), and a code called ECoPANN (Estimating Cosmological Parameters with ANN) is developed to achieve parameter inference. We test the ANN method by estimating the basic parameters of the concordance cosmological model using the simulated temperature power spectrum of the cosmic microwave background (CMB). The results show that the ANN performs excellently on best-fit values and errors of parameters, as well as correlations between parameters when compared with that of the Markov Chain Monte Carlo (MCMC) method. Besides, for a well-trained ANN model, it is capable of estimating parameters for multiple experiments that have different precisions, which can greatly reduce the consumption of time and computing resources for parameter inference. Furthermore, we extend the ANN to a multibranch network to achieve a joint constraint on parameters. We test the multibranch network using the simulated temperature and polarization power spectra of the CMB, Type Ia supernovae, and baryon acoustic oscillations, and almost obtain the same results as the MCMC method. Therefore, we propose that the ANN can provide an alternative way to accurately and quickly estimate cosmological parameters, and ECoPANN can be applied to the research of cosmology and even other broader scientific fields.