  We study the distribution of first-passage functionals ${\cal A}=
\int_0^{t_f} x^n(t)\, dt$, where $x(t)$ is a Brownian motion (with or without
drift) with diffusion constant $D$, starting at $x_0>0$, and $t_f$ is the
first-passage time to the origin. In the driftless case, we compute exactly,
for all $n>-2$, the probability density
$P_n(A|x_0)=\text{Prob}.(\mathcal{A}=A)$. This probability density has an
essential singular tail as $A\to 0$ and a power-law tail $\sim
A^{-(n+3)/(n+2)}$ as $A\to \infty$. The former is reproduced by the optimal
fluctuation method (OFM), which also predicts the optimal paths of the
conditioned process for small $A$. For the case with a drift toward the origin,
where no exact solution is known for general $n>-1$, the OFM predicts the
distribution tails. For $A\to 0$ it predicts the same essential singular tail
as in the driftless case. For $A\to \infty$ it predicts a stretched exponential
tail $-\ln P_n(A|x_0)\sim A^{1/(n+1)}$ for all $n>0$. In the limit of large
P\'eclet number $\text{Pe}= \mu x_0/(2D)\gg 1$, where $\mu$ is the drift
velocity, the OFM predicts a large-deviation scaling for all $A$: $-\ln
P_n(A|x_0)\simeq\text{Pe}\, \Phi_n\left(z= A/\bar{A}\right)$, where
$\bar{A}=x_0^{n+1}/{\mu(n+1)}$ is the mean value of $\mathcal{A}$. We compute
the rate function $\Phi_n(z)$ analytically for all $n>-1$. For $n>0$
$\Phi_n(z)$ is analytic for all $z$, but for $-1<n<0$ it is non-analytic at
$z=1$, implying a dynamical phase transition. The order of this transition is
$2$ for $-1/2<n<0$, while for $-1<n<-1/2$ the order of transition changes
continuously with $n$. Finally, we apply the OFM to the case of $\mu<0$ (drift
away from the origin). We show that, when the process is conditioned on
reaching the origin, the distribution of $\mathcal{A}$ coincides with the
distribution of $\mathcal{A}$ for $\mu>0$ with the same $|\mu|$.
