We propose an extended Hasegawa–Mima equation describing the evolution of nonlinear drift wave turbulence in general magnetic configurations. Such HMGM equation can be derived within the kinetic framework of guiding center motion or from a two-fluid model of an ion-electron plasma by application of a drift wave turbulence ordering that does not involve conditions on spatial derivatives of magnetic field and plasma density. The HMGM equation is therefore appropriate to describe the evolution of drift wave turbulence in strongly inhomogeneous magnetized plasmas, such as magnetospheric and stellarator plasmas, involving complex magnetic field geometries and non-uniform plasma density distributions. We find conservation laws (mass, energy, and generalized enstrophy) of the HMGM equation, study its algebraic (Hamiltonian) structure, and prove a nonlinear stability criterion for steady solutions through the energy-Casimir method. We then apply these results to describe drift waves and infer the existence of stable toroidal zonal flows with radial shear in dipole magnetic fields.