The probability measure $Q$ is the probability measure $P$ times the stochastic discount factor $M$ (but rescaled so $Q$ sums to 1).
Simple derivation
For maximum simplicity, I'll work in a discrete probability space with $n$ possible outcomes. Everything goes through under measure theory in more general, infinite dimensional probability spaces.
Let $\mathbf{x}$ be a vector denoting cashflows in those $n$ states. Let $\mathbf{p}$ be a vector denoting the probabilities of those $n$ states. Let $\mathbf{m}$ be a vector denoting the stochastic discount factor.
If a stochastic discount factor $\mathbf{m}$ exists, today's price of the future cashflow $\mathbf{x}$ is given by:
$$ f(\mathbf{x}) = \sum_i p_i m_i x_i $$
Now define $q_i = \frac{p_i m_i}{\sum_j p_j m_j}$. Also note that risk free rate must satisfy $1 = \sum_i p_i m_i r$. Hence $r = \frac{1}{\sum_i p_i m_i}$ and $\frac{q_i}{r} = p_i m_i $. Observe that $\mathbf{q}$ is also a probability vector since it sums to 1. Then: \begin{align*} f(\mathbf{x}) &= \sum_i p_i m_i x_i \\ &= \frac{1}{r}\sum_i q_i x_i \end{align*}
So the price of $\mathbf{x}$ is given by the expectation of $\mathbf{x}$ under the probability vector $\mathbf{q}$ discounted by the risk free rate.
The same logic goes through under measure theory (but you have a bit more formal mathematics with a radon-nikodym derivative etc...).
$$ \mathbb{E}^P[MX] = \frac{1}{r} \mathbb{E}^Q[X] \quad \quad \frac{dQ}{dP} = r M \quad \quad r = \frac{1}{\mathbb{E}^P[M]}$$
The whole idea is actually incredibly simple.