We consider the dynamic control problem of attaining a target position at a finite time T, while minimizing a linear-quadratic cost functional depending on the position and speed. We assume that the coefficients of the linear-quadratic cost functional are stochastic processes adapted to a Brownian filtration. We provide a probabilistic solution in terms of two coupled backward stochastic differential equations possessing a singularity at the terminal time T. We verify optimality of the candidate control by using a penalization argument. Special cases for which the problem has explicit solutions are discussed. Finally we illustrate our results in financial applications, where we derive optimal trading strategies for closing financial asset positions in markets with stochastic price impact and non-zero returns.