The dynamic model for large-eddy simulation of turbulence samples information from the resolved velocity field in order to optimize subgrid-scale model coefficients. When the method is used in conjunction with the Smagorinsky eddy-viscosity model, and the sampling process is formulated in a spatially local fashion, the resulting coefficient field is highly variable and contains a significant fraction of negative values. Negative eddy viscosity leads to computational instability and as a result the model is always augmented with a stabilization mechanism. In most applications the model is stabilized by averaging the relevant equations over directions of statistical homogeneity. While this approach is effective, and is consistent with the statistical basis underlying the eddy-viscosity model, it is not applicable to complex-geometry inhomogeneous flows. Existing local formulations, intended for inhomogeneous flows, are most commonly stabilized by artificially constraining the coefficient to be positive. In this paper we introduce a new dynamic model formulation, that combines advantages of the statistical and local approaches. We propose to accumulate the required averages over flow pathlines rather than over directions of statistical homogeneity. This procedure allows the application of the dynamic model with averaging to in-homogeneous flows in complex geometries. We analyse direct numerical simulation data to document the effects of such averaging on the Smagorinsky coefficient. The characteristic Lagrangian time scale over which the averaging is performed is chosen based on measurements of the relevant Lagrangian autocorrelation functions, and on the requirement that the model be purely dissipative, guaranteeing numerical stability when coupled with the Smagorinsky model. The formulation is tested in forced and decaying isotropic turbulence and in fully developed and transitional channel flow. In homogeneous flows, the results are similar to those of the volume-averaged dynamic model, while in channel flow, the predictions are slightly superior to those of the spatially (planar) averaged dynamic model. The relationship between the model and vortical structures in isotropic turbulence, as well as ejection events in channel flow, is investigated. Computational overhead is kept small (about 10% above the CPU requirements of the spatially averaged dynamic model) by using an approximate scheme to advance the Lagrangian tracking through first-order Euler time integration and linear interpolation in space.