Heterogeneous agent models are rapidly becoming the workhorse model of modern Macroeconomics but pose estimation challenges compared to their representative agent counterparts. This paper proposes a Machine Learning algorithm for the estimation of structural macroeconomic models. It is a simulation-based algorithm for maximum likelihood or Bayesian estimation, dubbed Sequential Neural Posterior Estimation (SNPE). The approach aims to simulate from the joint distribution of parameters and simulated data, then fits a conditional density estimator on the joint samples of the parameters conditional on the data to get the posterior. This algorithm has the following advantages: estimation is independent of and is unaffected by the choice of solution method or the inner workings of the model, it is faster and more accurate than current benchmark Bayesian algorithms, and simulation-based estimates are statistically efficient when well specified. For example, the posteriors estimated on the benchmark Smets-Wouters (2007) model are higher quality and faster compared to Metropolis-Hastings Markov Chain Monte Carlo. With Heterogeneous Agent New Keynesian (HANK) models, the estimation algorithm sidesteps lossy dimensionality reduction associated with Reiter’s method, and improves estimation speed of models solved via Winberry’s method by 13x per iteration. An empirical application estimating a full information heterogeneous agent model with both aggregate time series and cross sectional micro-data demonstrates the capability of this technique. A tutorial can be found at: https://shorturl.at/pMQ18