Let \(D_1\) and \(D_2\) be positive integers and let p be an odd prime number such that \(D:=D_1D_2\) is nonsquare and \(\gcd (D,2p)=1\) . Denote by \(N(D_1,D_2,4,p)\) the number of positive integer solutions (x, n) to the generalized Ramanujan–Nagell equation \(D_1x^2-D_2=4p^n\) . In this paper, we prove \(N(D_1,D_2,4,p)\le 4\) . Further, we prove that if the squarefree part of \(D_1\) is at most 1001, then \(N(D_1,D_2,4,p)\le 3\) .