An efficient and accurate finite-element method is presented for computing three-dimensional time-harmonic electromagnetic fields in strongly inhomogeneous, (an)isotropic media such as are encountered in the human body, subsurface structures of the Earth, and many engineering applications. For this purpose, two types of elements are used. In the domain of computation the corresponding program decides locally what type of element has to be used for obtaining the user-specified accuracy of modeling the field. In this way, optimum results are obtained both as regards computational efficiency and as regards desired accuracy. A method is introduced for imposing the divergence condition in a weighted sense. Numerical results are presented that demonstrate our approach to be efficient as well as accurate.