44 pages. To appear in American Journal of Mathematics. This is a substantial rewrite of our previous Arxiv article 0809.3704, taking into account subsequent developments, advice of colleagues and referee's commentsInternational audienceWe establish {\em{virtual surjection to pairs}} (VSP) as a general criterion for the finite presentability of subdirect products of groups: if $\Gamma_1,...,\Gamma_n$ are finitely presented and $S<\Gamma_1\times...\times\Gamma_n$ projects to a subgroup of finite index in each $\Gamma_i\times\Gamma_j$, then $S$ is finitely presentable, indeed there is an algorithm that will construct a finite presentation for $S$. We use the VSP criterion to characterise the finitely presented residually free groups. We prove that the class of such groups is recursively enumerable. We describe an algorithm that, given a finite presentation of a residually free group, constructs a canonical embedding into a direct product of finitely many limit groups. We solve the (multiple) conjugacy problem and membership problem for finitely presentable subgroups of residually free groups. We also prove that there is an algorithm that, given a finite generating set for such a subgroup, will construct a finite presentation. New families of subdirect products of free groups are constructed, including the first examples of finitely presented subgroups that are neither ${\rm{FP}}_\infty$ nor of Stallings-Bieri typ