In this paper we extend the quasitopological electromagnetism, recently introduced by H.-S. Liu et al. [arXiv:1907.10876], to arbitrary dimensions by introducing a fundamental $p$-form field. This allows us to construct new dyonic black hole solutions in odd dimensions, as well as regular $D$-dimensional black holes and solitons. The three-dimensional system consists of a Maxwell field interacting with a scalar field, leading to a deformation of the Ba\~nados-Teitelboim-Zanelli black hole. We present the general formulas defining the black hole solutions in arbitrary dimensions in Lovelock theory and explore the thermal properties of the asymptotically anti-de Sitter black holes in the gravitational framework of general relativity. In five dimensions, the latter black holes possess a rich phase space structure in the canonical ensemble, giving rise to as many as five different black hole phases at a fixed temperature, for a given range of the parameters.