Background: Riociguat and phosphodiesterase-5 inhibitors (PDE5i), approved for the treatment of pulmonary arterial hypertension (PAH), act on the same pathway via different mechanisms. Riociguat might be an alternative option for patients with PAH who do not respond sufficiently to treatment with PDE5i, but comparisons of the potential benefits of riociguat and PDE5i in these patients are needed. The aim of this trial was to assess the effects of switching to riociguat from PDE5i therapy versus continued PDE5i therapy in patients with PAH at intermediate risk of 1-year mortality. Methods: Riociguat rEplacing PDE5i therapy evaLuated Against Continued PDE5i thErapy (REPLACE) was an open-label, randomised controlled trial in 81 hospital-based pulmonary hypertension centres in 22 countries. The study enrolled patients aged 18–75 years with symptomatic PAH at intermediate risk of 1-year mortality (based on the European Society for Cardiology–European Respiratory Society guideline thresholds for WHO functional class and 6-min walk distance [6MWD]) who were receiving treatment with a PDE5i with or without an endothelin receptor antagonist for at least 6 weeks before randomisation. Patients were excluded if they had been previously treated with riociguat, had used prostacyclin analogues or prostacyclin receptor agonists within 30 days before randomisation, had clinically significant restrictive or obstructive parenchymal lung disease, or had left heart disease. Patients were randomly assigned (1:1) to remain on PDE5i treatment (oral sildenafil [≥60 mg per day] or oral tadalafil [20–40 mg per day]; the PDE5i group) or to switch to oral riociguat (up to 2·5 mg three times per day; the riociguat group), using an interactive voice and web response system, stratified by cause of PAH. The primary endpoint was clinical improvement by week 24, defined as an absence of clinical worsening and prespecified improvements in at least two of three variables (6MWD, WHO functional class, and N-terminal prohormone of brain natriuretic peptide), analysed using last observation carried forward in all randomly assigned patients with observed values at baseline and week 24 who received at least one dose of study medication (the full analysis set). Secondary endpoints included clinical worsening events. The trial has been completed and is registered with ClinicalTrials.gov, NCT02891850. Findings: Between Jan 11, 2017, and July 31, 2019, 293 patients were screened, of which 226 patients were randomly assigned to the riociguat group (n=111) or to the PDE5i group (n=115). 211 patients completed the study and 14 patients discontinued (seven in each group). One patient assigned to the PDE5i group did not receive treatment, so 225 patients were included in the safety analysis, and one further patient in the PDE5i group had missing components of the composite primary endpoint at baseline, so 224 patients were included in the full analysis set. The primary endpoint was met by 45 (41%) of 111 patients in the riociguat group and 23 (20%) of 113 patients in the PDE5i group; odds ratio [OR] 2·78 (95% CI 1·53–5·06; p=0·0007). Clinical worsening events occurred in one (1%) of 111 patients in the riociguat group (hospitalisation due to worsening PAH) and 10 (9%) of 114 patients in the PDE5i group (hospitalisation due to worsening PAH [n=9]; disease progression [n=1]; OR 0·10 [0·01–0·73]; p=0·0047). The most frequently occurring adverse events were hypotension (15 [14%]), headache (14 [13%]), and dyspepsia (10 [9%]) in the riociguat group, and headache (eight [7%]), cough (seven [6%]), and upper respiratory tract infection (seven [6%]) in the PDE5i group. Serious adverse events were reported in eight (7%) of 111 patients in the riociguat group and 19 (17%) of 114 patients in the PDE5i group. During the study, four patients died in the PDE5i group, one of them during the safety follow-up period. Interpretation: Switching to riociguat from PDE5i treatment, both of which act via the nitric oxide–soluble guanylate cyclase–cyclic guanosine monophosphate pathway, could be a strategic option for treatment escalation in patients with PAH at intermediate risk of 1-year mortality. Funding: Bayer AG, Merck Sharp & Dohme.