We study the occupation fluctuations of drifted Brownian motion in a closed interval, and show that they undergo a dynamical phase transition in the long-time limit without an additional low-noise limit. This phase transition is similar to wetting and depinning transitions, and arises here as a switching between paths of the random motion leading to different occupations. For low occupations, the motion essentially stays in the interval for some fraction of time before escaping, while for high occupations the motion is confined in an ergodic way in the interval. This is confirmed by studying a confined version of the model, which points to a further link between the dynamical phase transition and quantum phase transitions. Other variations of the model, including the geometric Brownian motion used in finance, are considered to discuss the role of recurrent and transient motion in dynamical phase transitions.