Primordial gravitational waves are expected to create a stochastic background encoding information about the early Universe that may not be accessible by other means. However, the primordial background is obscured by an astrophysical foreground consisting of gravitational waves from compact binaries. We demonstrate a Bayesian method for estimating the primordial background in the presence of an astrophysical foreground. Since the background and foreground signal parameters are estimated simultaneously, there is no subtraction step, and therefore we avoid astrophysical contamination of the primordial measurement, sometimes referred to as "residuals." Additionally, since we include the non-Gaussianity of the astrophysical foreground in our model, this method represents the statistically optimal approach to the simultaneous detection of a multicomponent stochastic background.