Quotients of standard Borel spaces Let $X$ and $Y$ be standard Borel spaces: topological spaces homeomorphic to Borel subsets of complete metric spaces. Given a surjective Borel map $f:X\to Y$, we get an equivalence relation $\sim_f\subseteq X^2$ given by $x\sim_fx'$ iff $f(x) = f(x')$. Since $\sim_f = (f\times f)^{-1}(\Delta_Y)$ where $\Delta_Y$ is the diagonal of $Y$, we obtain that $\sim_f$ is a Borel subset of $X$.
Now, let $\sim$ be any other equivalence on $X$ which is a Borel subset of $X^2$. Does there always exist a Borel space $Z$ and a Borel map $g:X\to Z$ such that $\sim = \sim_g$? Can we take $g$ to be surjective in such case? What conditions on $\sim$ are sufficient to ensure that $g$ can be chosen to be surjective?
If we could define a topological structure on $X/\!_\sim$ which turns it into a Borel space, then a natural projection $\pi:X\to X/\!_\sim$ would be a desired map $g$. 


*

*I think that if we endow $X/\!_\sim$ with the $\pi$-quotient topology, then will turn to be an analytic space, but not Borel in general. Is that correct? In such case, perhaps we can can take $Z$ being a one-point compactification of $X/\!_\sim$, though $g = \pi$ would fail to be surjective in such case.

*If endowing with the quotient topology only leads to analytic spaces, can we still introduce some different topology on $X/\!_\sim$ so that it becomes a Borel space and $\pi$ is a Borel map?
Edited: as Joel pointed out in his answer, the existence of $(g,Z)$ is equivalent to $\sim$ being smooth, that is there exists a Borel reduction from $\sim$ to $\mathrm{id}_Z$.
Kechris in his book "Classical Descriptive Set Theory" provides sufficient conditions for the smoothness in (18.20) such as existence of a Borel selector, or $\sim$ being a closed subset of a Polish space. Here by a selector is meant a map $h:X\to X$ such that $x\sim h(x)$ and $x\sim x'$ implies $h(x) = h(x')$. 
The existence $(g,Z)$ with surjective $g$ is a stronger version of smoothness requiring the existence of a surjective Borel reduction. Existence of a Borel selector of $\sim$ implies the existence such a reduction. The book of Kechris, e.g. (12.16), provides sufficient conditions for the existence of a Borel selector. The existence of surjective $g$ does not necessarily imply the existence of a Borel selector (see my comment to the OP).
The procedure via the quotient topology in 1.  may not work in some cases as to be analytic, $X/\!_\sim$ needs not only to be a quotient of a Borel space, but also countably separated.
 A: The answer is no, and this kind of question is part of the subject of the theory of Borel equivalence relations. 
The equivalence relations $\sim$ for which there is a Borel function $g:X\to Z$ into a standard Borel space $Z$, with $x\sim y\iff g(x)=g(y)$ are, by definition, precisely the smooth equivalence relations (see the definition on page 5 of the link above). But there are equivalence relations that are not smooth, such as the relation $E_0$ of eventual equality of infinite binary sequences. You can find the arguments that various relations are not smooth in the article to which I linked; see also page 5 of these notes of Simon Thomas and Scott Schneider; my favorite proof of this uses forcing (one adds a Cohen real, and sees where it maps in the extension, and then argues that that image real must be already in the ground model, which is impossible). 
The subject of Borel equivalence relations studies the entire hierarchy of Borel equivalence relations under Borel reducibility, which is a kind of complexity notion that in effect analyzes the relative difficulty of classification problems in mathematics, and the smooth equivalence relations occupy a region near the very bottom of the hierarchy, among the simplest relations. 
