Context. According to the magnetospheric accretion model, hot spots form on the surface of classical T Tauri stars (CTTSs) in regions where accreting disk material impacts the stellar surface at supersonic velocity, generating a shock. Aims. We investigate the dynamics and stability of postshock plasma that streams along nonuniform stellar magnetic fields at the impact region of accretion columns. We study how the magnetic field configuration and strength determine the structure, geometry, and location of the shock-heated plasma. Methods. We model the impact of an accretion stream onto the chromosphere of a CTTS by 2D axisymmetric magnetohydrodynamic simulations. Our model considers the gravity, the radiative cooling, and the magnetic-field-oriented thermal conduction (including the effects of heat flux saturation). We explore different configurations and strengths of the magnetic field. Results. The structure, stability, and location of the shocked plasma strongly depend on the configuration and strength of the magnetic field. In the case of weak magnetic fields (plasma β > ∼ 1 in the postshock region), a large component of B may develop perpendicular to the stream at the base of the accretion column, which limits the sinking of the shocked plasma into the chromosphere and perturbs the overstable shock oscillations induced by radiative cooling. An envelope of dense and cold chromospheric material may also develop around the shocked column. For strong magnetic fields (β < 1 in the postshock region close to the chromosphere), the field configuration determines the position of the shock and its stand-off height. If the field is strongly tapered close to the chromosphere, an oblique shock may form well above the stellar surface at the height where the plasma β ≈ 1. In general, we find that a nonuniform magnetic field makes the distribution of emission measure vs. temperature of the postshock plasma at T > 10 6 K lower than when there is uniform magnetic field. Conclusions. The initial magnetic field strength and configuration in the region of impact of the stream are expected to influence the chromospheric absorption and, therefore, the observability of the shock-heated plasma in the X-ray band. In addition, the field strength and configuration also influence the energy balance of the shocked plasma with its emission measure at T > 10 6 K, which is lower than expected for a uniform field. The above effects contribute to underestimating the mass accretion rates derived in the X-ray band.