Background: Patients with HER2-positive metastatic breast cancer have a high risk of developing brain metastases. Efficacious treatment options are scarce. We investigated the activity and safety of pyrotinib plus capecitabine in patients with HER2-positive metastatic breast cancer and brain metastases. Methods: We did a multicentre, single-arm, two-cohort, phase 2 trial in eight tertiary hospitals in China. Patients aged 18 years or older who had radiotherapy-naive HER2-positive brain metastases (cohort A) or progressive disease after radiotherapy (cohort B), with an Eastern Cooperative Oncology Group performance status of 0–2, received pyrotinib 400 mg orally once daily, and capecitabine 1000 mg/m2 orally twice daily for 14 days, followed by 7 days off every 3 weeks until disease progression or unacceptable toxicity. The primary endpoint was confirmed intracranial objective response rate by investigator assessment according to the Response Evaluation Criteria In Solid Tumours (version 1.1). Activity and safety were analysed in patients with at least one dose of study drug. The study is ongoing, but recruitment is complete. The study is registered with ClinicalTrials.gov, NCT03691051. Findings: Between Jan 29, 2019, and July 10, 2020, we enrolled 78 women: 51 (86%) of 59 patients in cohort A and 18 (95%) of 19 patients in cohort B had previous exposure to trastuzumab. Median follow-up duration was 15·7 months (IQR 9·7–19·0). The intracranial objective response rate was 74·6% (95% CI 61·6–85·0; 44 of 59 patients) in cohort A and 42·1% (20·3–66·5; eight of 19 patients) in cohort B. The most common grade 3 or worse treatment-emergent adverse event was diarrhoea (14 [24%] in cohort A and four [21%] in cohort B). Two (3%) patients in cohort A and three (16%) in cohort B had treatment-related serious adverse events. No treatment-related deaths occurred. Interpretation: To our knowledge, this is the first prospective study showing the activity and safety of pyrotinib plus capecitabine in patients with HER2-positive breast cancer and brain metastases, especially in radiotherapy-naive population. This combination deserves further validation in a randomised, controlled trial. Funding: National Cancer Centre Climbing Foundation Key Project of China, Jiangsu Hengrui Pharmaceuticals. Translation: For the Chinese translation of the abstract see Supplementary Materials section.