The dynamics of the interaction of a quantized cavity field and the vibronic degrees of freedom of a trapped ion is studied under realistic conditions by including cavity losses, spontaneous electronic transitions, and atomic nonlinearities. As long as spontaneous electronic transitions are negligible, analytical results are derived for describing the interaction of the trapped ion and the damped cavity field in the secular approximation. Under more general conditions, when the secular approximation breaks down and spontaneous emission effects become important, the dynamics of the system is studied by quantum-trajectory methods. As an example we demonstrate that, by exploiting the nonlinearities inherent in the dynamics of the system, one may prepare correlated vibronic states and vibrational Fock states. Moreover, we study the generation of an entangled Greenberger-Horne-Zeilinger state. Taking into account the decoherence due to electronic and cavity losses, the best fidelity is obtained under conditions far from the Lamb-Dicke regime.