An increased risk of breast cancer is associated with high serum concentrations of oestradiol and testosterone in postmenopausal women, but little is known about how these hormones affect response to endocrine therapy for breast cancer prevention or treatment. We aimed to assess the effects of serum oestradiol and testosterone concentrations on the efficacy of the aromatase inhibitor anastrozole for the prevention of breast cancer in postmenopausal women at high risk. In this case-control study we used data from the IBIS-II prevention trial, a randomised, controlled, double-blind trial in postmenopausal women aged 40-70 years at high risk of breast cancer, conducted in 153 breast cancer treatment centres across 18 countries. In the trial, women were randomly assigned (1:1) to receive anastrozole (1 mg/day, orally) or placebo daily for 5 years. In this pre-planned case-control study, the primary analysis was the effect of the baseline oestradiol to sex hormone binding globulin (SHBG) ratio (oestradiol-SHBG ratio) on the development of all breast cancers, including ductal carcinoma in situ (the primary endpoint in the trial). Cases were participants in whom breast cancer was reported after trial entry and until the cutoff on Oct 22, 2019, and who had valid blood samples and no use of hormone replacement therapy within 3 months of trial entry or during the trial. For each case, two controls without breast cancer were selected at random, matched on treatment group, age (within 2 years), and follow-up time (at least that of the matching case). For each treatment group, we applied a multinominal logistic regression likelihood-ratio trend test to assess what change in the proportion of cases was associated with a one-quartile change in hormone ratio. Controls were used only to determine quartile cutoffs. Profile likelihood 95% CIs were used to indicate the precision of estimates. A secondary analysis also investigated the effect of the baseline testosterone-SHBG ratio on breast cancer development. We also assessed relative benefit of anastrozole versus placebo (calculated as 1 - the ratio of breast cancer cases in the anastrozole group to cases in the placebo group). The trial was registered with ISRCTN (number ISRCTN31488319) and completed recruitment on Jan 31, 2012, but long-term follow-up is ongoing. 3864 women were recruited into the trial between Feb 2, 2003, and Jan 31, 2012, and randomly assigned to receive anastrozole (n=1920) or placebo (n=1944). Median follow-up time was 131 months (IQR 106-156), during which 85 (4·4%) cases of breast cancer in the anastrozole group and 165 (8·5%) in the placebo group were identified. No data on gender, race, or ethnicity were collected. After exclusions, the case-control study included 212 participants from the anastrozole group (72 cases, 140 controls) and 416 from the placebo group (142 cases, 274 controls). A trend of increasing breast cancer risk with increasing oestradiol-SHBG ratio was found in the placebo group (trend per quartile 1·25 [95% CI 1·08 to 1·45], p=0·0033), but not in the anastrozole group (1·06 [0·86 to 1·30], p=0·60). A weaker effect was seen for the testosterone-SHBG ratio in the placebo group (trend 1·21 [1·05 to 1·41], p=0·011), but again not in the anastrozole group (trend 1·18 [0·96 to 1·46], p=0·11). A relative benefit of anastrozole was seen in quartile 2 (0·55 [95% CI 0·13 to 0·78]), quartile 3 (0·54 [0·22 to 0·74], and quartile 4 (0·56 [0·23 to 0·76]) of oestradiol-SHBG ratio, but not in quartile 1 (0·18 [-0·60 to 0·59]). These results suggest that serum hormones should be measured more routinely and integrated into risk management decisions. Measuring serum hormone concentrations is inexpensive and might help clinicians differentiate which women will benefit most from an aromatase inhibitor. Cancer Research UK, National Health and Medical Research Council (Australia), Breast Cancer Research Foundation, and DaCosta Fund.