Edit: I have just figured a much easier way.
So, I edited the answer.
Let $\mathcal{V} = \{V_n : n = 1, 2, \dotsc\}$
be a countable base for the topology of $Y$.
For each $V_n$, choose a negligible $E_n \subset X$ such that
$f^{-1}(V_n) \setminus E_n \in \mathcal{F}$.
It may happen that $\bigcup E_n \not \in \mathcal{F}$.
But since it is a negligible set, there is a negligible
$Z \in \mathcal{F}$ such that $\bigcup E_n \subset Z$.
Fix some $y \in Y$,
and then define
$$
g(x)
=
\left\{
\begin{array}{}
f(x), & x \not \in Z
\\
y, & x \in Z
\end{array}
\right.
$$
Notice that for any $V_n \in \mathcal{V}$,
if $y \not \in V_n$,
$$
\begin{align*}
g^{-1}(V_n)
&=
f^{-1}(V_n) \setminus Z
\\&=
(f^{-1}(V_n) \setminus E_n) \setminus Z
\in \mathcal{F}.
\end{align*}
$$
And if $y \in V_n$,
$$
\begin{align*}
g^{-1}(V_n)
&=
f^{-1}(V_n) \cup Z
\\&=
(f^{-1}(V_n) \setminus E_n) \cup Z
\in \mathcal{F}.
\end{align*}
$$
That is, $g^{-1}(\mathcal{V}) \subset \mathcal{F}$.
All open sets of $Y$ are (countable) union of elements in $\mathcal{V}$.
Therefore, $\mathcal{V}$ generates the $\sigma$-algebra of Borel sets
$\mathcal{B}$.
And so, $g$ is $\mathcal{F}$-measurable.
In fact,
$$
g^{-1}(\mathcal{B})
=
g^{-1}(\sigma(\mathcal{V}))
=
\sigma \left(g^{-1}(\mathcal{V})\right)
\subset \mathcal{F}.
$$
Since it is evident that $g$ and $f$ are equal almost everywhere,
the proof is complete.