Wang and Ye [Adv. Math. 230 (2012), pp. 294–320] prove a Hardy–Moser–Trudinger inequality in dimension two which improves both the classical Moser–Trudinger inequality and the classical Hardy inequality in the unit disc. In this paper, we generalize their result both to the higher dimensional unit ball and to the singular weighted cases as well. More precisely, we prove that \[ sup u ∈ W 0 1 , n ( B n ) , ∫ B n | ∇ u | n d x − ( 2 ( n − 1 ) n ) n ∫ B n | u | n ( 1 − | x | 2 ) n d x ≤ 1 ∫ B n e ( 1 − β n ) α n | u | n n − 1 | x | − β d x ≤ C \sup _{\substack {u\in W^{1,n}_0(\mathbb {B}^n),\\ \int _{\mathbb {B}^n} |\nabla u|^n dx -\left (\frac {2(n-1)}n\right )^n \int _{\mathbb {B}^n} \frac {|u|^n}{(1-|x|^2)^n} dx \leq 1}}\int _{\mathbb {B}^n} e^{(1-\frac \beta n)\alpha _n |u|^{\frac n{n-1}}} |x|^{-\beta } dx \leq C \] for any β ∈ [ 0 , n ) \beta \in [0,n) , n ≥ 3 n\geq 3 where α n = n ω n − 1 1 n − 1 \alpha _n = n \omega _{n-1}^{\frac 1{n-1}} and ω n − 1 \omega _{n-1} is the surface area of the n − 1 n-1 dimensional unit sphere. The proof of Wang and Ye is based on the blow-up analysis method which seems not work in the higher dimensions. In this paper, we propose a new approach based on the method of transplantation of Green’s functions to prove our inequality. As a consequence, we obtain a singular Moser–Trudinger inequality in the hyperbolic spaces which confirms affirmatively a conjecture by Mancini, Sandeep and Tintarev [Adv. Nonlinear Anal., 2 (2013), pp. 309–324].