The spectroscopic Sloan Digital Sky Survey (SDSS) Data Release 7 (DR7)galaxy sample represents the final set of galaxies observed using theoriginal SDSS target selection criteria. We analyse the clustering ofgalaxies within this sample, including both the luminous red galaxy andmain samples, and also include the 2-degree Field Galaxy Redshift Surveydata. In total, this sample comprises 893319 galaxies over9100deg2. Baryon acoustic oscillations (BAO) are observed inpower spectra measured for different slices in redshift; this allows usto constrain the distance-redshift relation at multiple epochs. Weachieve a distance measure at redshift z = 0.275, ofrs(zd)/DV(0.275) = 0.1390 +/- 0.0037(2.7 per cent accuracy), where rs(zd) is thecomoving sound horizon at the baryon-drag epoch, DV(z)≡ [(1 +z)2D2Acz/H(z)]1/3,DA(z) is the angular diameter distance and H(z) is the Hubbleparameter. We find an almost independent constraint on the ratio ofdistances DV(0.35)/DV(0.2) = 1.736 +/- 0.065,which is consistent at the 1.1σ level with the best-fittingΛ cold dark matter model obtained when combining our z = 0.275distance constraint with the Wilkinson Microwave Anisotropy Probe 5-year(WMAP5) data. The offset is similar to that found in previous analysesof the SDSS DR5 sample, but the discrepancy is now of lowersignificance, a change caused by a revised error analysis and a changein the methodology adopted, as well as the addition of more data. UsingWMAP5 constraints on Ωbh2 andΩch2, and combining our BAO distancemeasurements with those from the Union supernova sample, places a tightconstraint on Ωm = 0.286 +/- 0.018 and H0 =68.2 +/- 2.2kms-1Mpc-1 that is robust to allowingΩk ≠ 0 and w ≠ -1. This result is independent ofthe behaviour of dark energy at redshifts greater than those probed bythe BAO and supernova measurements. Combining these data sets with thefull WMAP5 likelihood constraints provides tight constraints on bothΩk = -0.006 +/- 0.008 and w = -0.97 +/- 0.10 for aconstant dark energy equation of state.