Background: In ROCKET AF, rivaroxaban was non-inferior to adjusted-dose warfarin in preventing stroke or systemic embolism among patients with atrial fibrillation (AF). We aimed to investigate whether the efficacy and safety of rivaroxaban compared with warfarin is consistent among the subgroups of patients with and without previous stroke or transient ischaemic attack (TIA). Methods: In ROCKET AF, patients with AF who were at increased risk of stroke were randomly assigned (1:1) in a double-blind manner to rivaroxaban 20 mg daily or adjusted dose warfarin (international normalised ratio 2·0-3·0). Patients and investigators were masked to treatment allocation. Between Dec 18, 2006, and June 17, 2009, 14 264 patients from 1178 centres in 45 countries were randomly assigned. The primary endpoint was the composite of stroke or non-CNS systemic embolism. In this substudy we assessed the interaction of the treatment effects of rivaroxaban and warfarin among patients with and without previous stroke or TIA. Efficacy analyses were by intention to treat and safety analyses were done in the on-treatment population. ROCKET AF is registered with ClinicalTrials.gov, number NCT00403767. Findings: 7468 (52%) patients had a previous stroke (n=4907) or TIA (n=2561) and 6796 (48%) had no previous stroke or TIA. The number of events per 100 person-years for the primary endpoint in patients treated with rivaroxaban compared with warfarin was consistent among patients with previous stroke or TIA (2·79% rivaroxaban vs 2·96% warfarin; hazard ratio [HR] 0·94, 95% CI 0·77-1·16) and those without (1·44% vs 1·88%; 0·77, 0·58-1·01; interaction p=0·23). The number of major and non-major clinically relevant bleeding events per 100 person-years in patients treated with rivaroxaban compared with warfarin was consistent among patients with previous stroke or TIA (13·31% rivaroxaban vs 13·87% warfarin; HR 0·96, 95% CI 0·87-1·07) and those without (16·69% vs 15·19%; 1·10, 0·99-1·21; interaction p=0·08). Interpretation: There was no evidence that the relative efficacy and safety of rivaroxaban compared with warfarin was different between patients who had a previous stroke or TIA and those who had no previous stroke or TIA. These results support the use of rivaroxaban as an alternative to warfarin for prevention of recurrent as well as initial stroke in patients with AF. Funding: Johnson and Johnson Pharmaceutical Research and Development and Bayer HealthCare.