To improve the simulation of nonlinear aspects of the flow over steep topography, a potential enstrophy and energy conserving scheme for the shallow water equations is derived. It is pointed out that a family of schemes can conserve total energy for general flow and potential enstrophy for flow with no mass flux divergence. The newly derived scheme is a unique member of this family, that conserves both potential enstrophy and energy for general flow. Comparison by means of numerical experiment with a scheme that conserves (potential) enstrophy for purely horizontal nondivergent flow demonstrated the considerable superiority of the newly derived potential enstrophy and energy conserving scheme, not only in suppressing a spurious energy cascade but also in determining the overall flow regime. The potential enstrophy and energy conserving scheme for a spherical grid is also presented.