This paper investigates the dynamics of a Duffing oscillator excited by an unbalanced motor. The interaction between motor and vibrating system is considered as nonideal, which means that the excitation provided by the motor can be influenced by the vibrating response, as is the case in general for real systems. This constitutes an important difference with respect to the classical (ideally excited) Duffing oscillator, where the amplitude and frequency of the external forcing are assumed to be known a priori. Starting from pre-resonant initial conditions, we investigate the phenomena of passage through resonance (the system evolves towards a post-resonant state after some transient near-resonant oscillations) and resonant capture (the system gets locked into a near-resonant stationary oscillation). The stability of stationary solutions is analytically studied in detail through averaging procedures, and the obtained results are confirmed by numerical simulations.