Many problems at the forefront of theoretical astrophysics require the treatment of magnetized fluids in dynamical, strongly curved spacetimes. Such problems include the origin of gamma-ray bursts, magnetic braking of differential rotation in nascent neutron stars arising from stellar core collapse or binary neutron star merger, the formation of jets and magnetized disks around newborn black holes, etc. To model these phenomena, all of which involve both general relativity (GR) and magnetohydrodynamics (MHD), we have developed a GRMHD code capable of evolving MHD fluids in dynamical spacetimes. Our code solves the Einstein-Maxwell-MHD system of coupled equations in axisymmetry and in full 3+1 dimensions. We evolve the metric by integrating the BSSN equations, and use a conservative, shock-capturing scheme to evolve the MHD equations. Our code gives accurate results in standard MHD code-test problems, including magnetized shocks and magnetized Bondi flow. To test our code's ability to evolve the MHD equations in a dynamical spacetime, we study the perturbations of a homogeneous, magnetized fluid excited by a gravitational plane wave, and we find good agreement between the analytic and numerical solutions.