The paper presents a statistical method for determining a specific variation of random excitations that leads to large transient enhancements (peaks) of a particular dynamical response in a stochastic mechanical system. Such a variation is found by calculating the weighted mean of the excitation variations close to a small number of largest peaks of the response obtained for a single long realization of the system motion. This statistical formula is derived by using the conditional expectation with respect to the rare event of unusually large response values and the ergodic theorem; optionally, a minimal interpeak distance is introduced. A similar formula gives the specific variations of other system variables around the peaks, and it can also be generalized to investigate any multivariable stochastic dynamical system or any set of correlated random signals. This method is applied to transient enhancements of quantities related to running safety and ride comfort of a railway vehicle: the derailment coefficient and the vertical acceleration of the vehicle body, respectively, obtained in simulations of the vehicle motion along a track with random irregularities. The averaged variations of the lateral irregularities and track superelevation close to the track locations of largest peaks of the derailment coefficient show characteristic oscillations leading to enhanced wheelset hunting in a short track section before the peak occurrence. A different pattern is found for the average variation of vertical track irregularities in the vicinity of the track points where largest maxima (or minima) of the vertical body acceleration occur.