This relation can be obtained if we realize that Total Cost can be written as a function of output (which in turn is a function of input factors), but also, that Total Cost equals total payments to factors of production. In real terms,
$$TC=TC(Q) = (w/p)N + (r/p)K$$
with the payment rates exogenous. But $Q = Q(N,K)$. Differentiate both sides by $N$:
$$\frac {\partial TC(Q(N,K))}{\partial N} = w/p $$
$$\Rightarrow \frac {\partial TC(Q(N,K))}{\partial Q}\cdot \frac {\partial Q(N,K)}{\partial N} = w/p$$
$$\Rightarrow MC \cdot MPN = w/p \Rightarrow MC = \frac {w/p}{MPN}$$
One can perform the same exercise to obtain the analogous relation with respect to capital:
$$MC = \frac {r/p}{MPK}$$