Choose a compactification $U_i \subset X_i$ over $B$ for $i = 1, 2$. We may assume $U_i$ is scheme theoretically dense in $X_i$. We may assume there is an open $V_i \subset X_i$ and a proper morphism $\psi_i : V_i \to U$ extending $U_i \to U$, see Lemma \ref{lemma-compactification-dominates}. Picture $$ \xymatrix{ U_i \ar[r] \ar[d] & V_i \ar[r] \ar[dl]^{\psi_i} & X_i \\ U } $$ Denote $Z_1 \subset U$ the reduced closed subspace corresponding to the closed subset $|U| \setminus |U_2|$. Recall that $f^{-1}Z_1$ is a closed subspace of $U_1$ mapping isomorphically to $Z_1$. Denote $Z_2 \subset U$ the reduced closed subspace corresponding to the closed subset $|U| \setminus \Im(|f|) = |U_2| \setminus \Im(|U_1 \times_U U_2| \to |U_2|)$. Thus we have $$ U = U_2 \amalg Z_1 = Z_2 \amalg \Im(f) = Z_2 \amalg \Im(U_1 \times_U U_2 \to U_2) \amalg Z_1 $$ set theoretically. Denote $Z_{i, i} \subset V_i$ the inverse image of $Z_i$ under $\psi_i$. Observe that $\psi_2$ is an isomorphism over an open neighbourhood of $Z_2$. Observe that $Z_{1, 1} = \psi_1^{-1}Z_1 = f^{-1}Z_1 \amalg T$ for some closed subspace $T \subset V_1$ disjoint from $f^{-1}Z_1$ and furthermore $\psi_1$ is \'etale along $f^{-1}Z_1$. Denote $Z_{i, j} \subset V_i$ the inverse image of $Z_j$ under $\psi_i$. Observe that $\psi_i : Z_{i, j} \to Z_j$ is a proper morphism. Since $Z_i$ and $Z_j$ are disjoint closed subspaces of $U$, we see that $Z_{i, i}$ and $Z_{i, j}$ are disjoint closed subspaces of $V_i$. \medskip\noindent Denote $\overline{Z}_{i, i}$ and $\overline{Z}_{i, j}$ the scheme theoretic images of $Z_{i, i}$ and $Z_{i, j}$ in $X_i$. We recall that $|Z_{i, j}|$ is dense in $|\overline{Z}_{i, j}|$, see Morphisms of Spaces, Lemma \ref{spaces-morphisms-lemma-quasi-compact-immersion}. After replacing $X_i$ by a $V_i$-admissible blowup we may assume that $\overline{Z}_{i, i}$ and $\overline{Z}_{i, j}$ are disjoint, see Lemma \ref{lemma-separate-disjoint-locally-closed-by-blowing-up}. We assume this holds for both $X_1$ and $X_2$. Observe that this property is preserved if we replace $X_i$ by a further $V_i$-admissible blowup. Hence we may replace $X_1$ by another $V_1$-admissible blowup and assume $|\overline{Z}_{1, 1}|$ is the disjoint union of the closures of $|T|$ and $|f^{-1}Z_1|$ in $|X_1|$. \medskip\noindent Set $V_{12} = V_1 \times_U V_2$. We have an immersion $V_{12} \to X_1 \times_B X_2$ which is the composition of the closed immersion $V_{12} = V_1 \times_U V_2 \to V_1 \times_B V_2$ (Morphisms of Spaces, Lemma \ref{spaces-morphisms-lemma-fibre-product-after-map}) and the open immersion $V_1 \times_B V_2 \to X_1 \times_B X_2$. Let $X_{12} \subset X_1 \times_B X_2$ be the scheme theoretic image of $V_{12} \to X_1 \times_B X_2$. The projection morphisms $$ p_1 : X_{12} \to X_1 \quad\text{and}\quad p_2 : X_{12} \to X_2 $$ are proper as $X_1$ and $X_2$ are proper over $B$. If we replace $X_1$ by a $V_1$-admissible blowing up, then $X_{12}$ is replaced by the strict transform with respect to this blowing up, see Lemma \ref{lemma-replaced-by-strict-transform}. \medskip\noindent Denote $\psi : V_{12} \to U$ the compositions $\psi = \psi_1 \circ p_1|_{V_{12}} = \psi_2 \circ p_2|_{V_{12}}$. Consider the closed subspace $$ Z_{12, 2} = (p_1|_{V_{12}})^{-1}Z_{1, 2} = (p_2|_{V_{12}})^{-1}Z_{2, 2} = \psi^{-1}Z_2 \subset V_{12} $$ The morphism $p_1|_{V_{12}} : V_{12} \to V_1$ is an isomorphism over an open neighbourhood of $Z_{1, 2}$ because $\psi_2 : V_2 \to U$ is an isomorphism over an open neighbourhood of $Z_2$ and $V_{12} = V_1 \times_U V_2$. By Lemma \ref{lemma-blowup-iso-along} there exists a $V_1$-admissible blowing up $X_1' \to X_1$ such that the strict tranform $p'_1 : X'_{12} \to X'_1$ of $p_1$ is an isomorphism over an open neighbourhood of the closure of $|Z_{1, 2}|$ in $|X'_1|$. After replacing $X_1$ by $X'_1$ and $X_{12}$ by $X'_{12}$ we may assume that $p_1$ is an isomorphism over an open neighbourhood of $|\overline{Z}_{1, 2}|$. \medskip\noindent The result of the previous paragraph tells us that $$ X_{12} \cap (\overline{Z}_{1, 2} \times_B \overline{Z}_{2, 1}) = \emptyset $$ where the intersection taken in $X_1 \times_B X_2$. Namely, the inverse image $p_1^{-1}\overline{Z}_{1, 2}$ in $X_{12}$ maps isomorphically to $\overline{Z}_{1, 2}$. In particular, we see that $|Z_{12, 2}|$ is dense in $|p_1^{-1}\overline{Z}_{1, 2}|$. Thus $p_2$ maps $|p_1^{-1}\overline{Z}_{1, 2}|$ into $|\overline{Z}_{2, 2}|$. Since $|\overline{Z}_{2, 2}| \cap |\overline{Z}_{2, 1}| = \emptyset$ we conclude. \medskip\noindent It turns out that we need to do one additional blowing up before we can conclude the argument. Namely, let $V_2 \subset W_2 \subset X_2$ be the open subspace with underlying topological space $$ |W_2| = |V_2| \cup (|X_2| \setminus |\overline{Z}_{2, 1}|) = |X_2| \setminus \left(|\overline{Z}_{2, 1}| \setminus |Z_{2, 1}|\right) $$ Since $p_2(p_1^{-1}\overline{Z}_{1, 2})$ is contained in $W_2$ (see above) we see that replacing $X_2$ by a $W_2$-admissible blowup and $X_{21}$ by the corresponding strict transform will preserve the property of $p_1$ being an isomorphism over an open neighbourhood of $\overline{Z}_{1, 2}$. Since $\overline{Z}_{2, 1} \cap W_2 = \overline{Z}_{2, 1} \cap V_2 = Z_{2, 1}$ we see that $Z_{2, 1}$ is a closed subspace of $W_2$ and $V_2$. Observe that $V_{12} = V_1 \times_U V_2 = p_1^{-1}(V_1) = p_2^{-1}(V_2)$ as open subspaces of $X_{12}$ as it is the largest open subspace of $X_{12}$ over which the morphism $\psi : V_{12} \to U$ extends; details omitted\footnote{Namely, $V_1 \times_U V_2$ is proper over $U$ so if $\psi$ extends to a larger open of $X_{12}$, then $V_1 \times_U V_2$ would be closed in this open by Morphisms of Spaces, Lemma \ref{spaces-morphisms-lemma-universally-closed-permanence}. Then we get equality as $V_{12} \subset X_{12}$ is dense.}. We have the following equalities of closed subspaces of $V_{12}$: $$ p_2^{-1}Z_{2, 1} = p_2^{-1} \psi_2^{-1} Z_1 = p_1^{-1} \psi_1^{-1} Z_1= p_1^{-1}Z_{1, 1} = p_1^{-1}f^{-1}Z_1 \amalg p_1^{-1}T $$ Here and below we use the slight abuse of notation of writing $p_2$ in stead of the restriction of $p_2$ to $V_{12}$, etc. Since $p_2^{-1}(Z_{2, 1})$ is a closed subspace of $p_2^{-1}(W_2)$ as $Z_{2, 1}$ is a closed subspace of $W_2$ we conclude that also $p_1^{-1}f^{-1}Z_1$ is a closed subspace of $p_2^{-1}(W_2)$. Finally, the morphism $p_2 : X_{12} \to X_2$ is \'etale at points of $p_1^{-1}f^{-1}Z_1$ as $\psi_1$ is \'etale along $f^{-1}Z_1$ and $V_{12} = V_1 \times_U V_2$. Thus we may apply Lemma \ref{lemma-blowup-etale-along} to the morphism $p_2 : X_{12} \to X_2$, the open $W_2$, the closed subspace $Z_{2, 1} \subset W_2$, and the closed subspace $p_1^{-1}f^{-1}Z_1 \subset p_2^{-1}(W_2)$. Hence after replacing $X_2$ by a $W_2$-admissible blowup and $X_{12}$ by the corresponding strict transform, we obtain for every geometric point $\overline{y}$ of the closure of $|p_1^{-1}f^{-1}Z_1|$ a local ring map $\mathcal{O}_{X_{12}, \overline{y}} \to \mathcal{O}$ such that $\mathcal{O}_{X_2, p_2(\overline{y})} \to \mathcal{O}$ is finite flat. \medskip\noindent Consider the algebraic space $$ W_2 = U \coprod\nolimits_{U_2} (X_2 \setminus \overline{Z}_{2, 1}), $$ and with $T \subset V_1$ as in the first paragraph the algebraic space $$ W_1 = U \coprod\nolimits_{U_1} (X_1 \setminus \overline{Z}_{1, 2} \cup \overline{T}), $$ obtained by pushout, see Lemma \ref{lemma-construct-elementary-distinguished-square}. Let us apply Lemma \ref{lemma-check-separated} to see that $W_i \to B$ is separated. First, $U \to B$ and $X_i \to B$ are separated. Let us check the quasi-compact immersion $U_i \to U \times_B (X_i \setminus \overline{Z}_{i, j})$ is closed using the valuative criterion, see Morphisms of Spaces, Lemma \ref{spaces-morphisms-lemma-quasi-compact-existence-universally-closed}. Choose a valuation ring $A$ over $B$ with fraction field $K$ and compatible morphisms $(u, x_i) : \Spec(A) \to U \times_B X_i$ and $u_i : \Spec(K) \to U_i$. Since $\psi_i$ is proper, we can find a unique $v_i : \Spec(A) \to V_i$ compatible with $u$ and $u_i$. Since $X_i$ is proper over $B$ we see that $x_i = v_i$. If $v_i$ does not factor through $U_i \subset V_i$, then we conclude that $x_i$ maps the closed point of $\Spec(A)$ into $Z_{i, j}$ or $T$ when $i = 1$. This finishes the proof because we removed $\overline{Z}_{i, j}$ and $\overline{T}$ in the construction of $W_i$. \medskip\noindent On the other hand, for any valuation ring $A$ over $B$ with fraction field $K$ and any morphism $$ \gamma : \Spec(K) \to \Im(U_1 \times_U U_2 \to U) $$ over $B$, we claim that after replacing $A$ by an extension of valuation rings, there is an $i$ and an extension of $\gamma$ to a morphism $h_i : \Spec(A) \to W_i$. Namely, we first extend $\gamma$ to a morphism $g_2 : \Spec(A) \to X_2$ using the valuative criterion of properness. If the image of $g_2$ does not meet $\overline{Z}_{2, 1}$, then we obtain our morphism into $W_2$. Otherwise, denote $\overline{z} \in \overline{Z}_{2, 1}$ a geometric point lying over the image of the closed point under $g_2$. We may lift this to a geometric point $\overline{y}$ of $X_{12}$ in the closure of $|p_1^{-1}f^{-1}Z_1|$ because the map of spaces $|p_1^{-1}f^{-1}Z_1| \to |\overline{Z}_{2, 1}|$ is closed with image containing the dense open $|Z_{2, 1}|$. After replacing $A$ by its strict henselization (More on Algebra, Lemma \ref{more-algebra-lemma-henselization-valuation-ring}) we get the following diagram $$ \xymatrix{ A \ar@{..>}[rr] & & A' \\ \mathcal{O}_{X_2, \overline{z}} \ar[r] \ar[u] & \mathcal{O}_{X_{12}, \overline{y}} \ar[r] & \mathcal{O} \ar@{..>}[u] } $$ where $\mathcal{O}_{X_{12}, \overline{y}} \to \mathcal{O}$ is the map we found in the 5th paragraph of the proof. Since the horizontal composition is finite and flat we can find an extension of valuation rings $A'/A$ and dotted arrow making the diagram commute. After replacing $A$ by $A'$ this means that we obtain a lift $g_{12} : \Spec(A) \to X_{12}$ whose closed point maps into the closure of $|p_1^{-1}f^{-1}Z_1|$. Then $g_1 = p_1 \circ g_{12} : \Spec(A) \to X_1$ is a morphism whose closed point maps into the closure of $|f^{-1}Z_1|$. Since the closure of $|f^{-1}Z_1|$ is disjoint from the closure of $|T|$ and contained in $|\overline{Z}_{1, 1}|$ which is disjoint from $|\overline{Z}_{1, 2}|$ we conclude that $g_1$ defines a morphism $h_1 : \Spec(A) \to W_1$ as desired. \medskip\noindent Consider a diagram $$ \xymatrix{ W_1' \ar[d] \ar[r] & W & W_2' \ar[l] \ar[d] \\ W_1 & U \ar[l] \ar[lu] \ar[u] \ar[ru] \ar[r] & W_2 } $$ as in More on Morphisms of Spaces, Lemma \ref{spaces-more-morphisms-lemma-find-common-blowups}. By the previous paragraph for every solid diagram $$ \xymatrix{ \Spec(K) \ar[r]_\gamma  \ar[d] & W \ar[d] \\ \Spec(A) \ar@{..>}[ru] \ar[r] & B } $$ where $\Im(\gamma) \subset \Im(U_1 \times_U U_2 \to U)$ there is an $i$ and an extension $h_i : \Spec(A) \to W_i$ of $\gamma$ after possibly replacing $A$ by an extension of valuation rings. Using the valuative criterion of properness for $W'_i \to W_i$, we can then lift $h_i$ to $h'_i : \Spec(A) \to W'_i$. Hence the dotted arrow in the diagram exists after possibly extending $A$. Since $W$ is separated over $B$, we see that the choice of extension isn't needed and the arrow is unique as well, see Morphisms of Spaces, Lemmas \ref{spaces-morphisms-lemma-usual-enough} and \ref{spaces-morphisms-lemma-separated-implies-valuative}. Then finally the existence of the dotted arrow implies that $W \to B$ is universally closed by Morphisms of Spaces, Lemma \ref{spaces-morphisms-lemma-refined-valuative-criterion-universally-closed}. As $W \to B$ is already of finite type and separated, we win.