Background Many male prison leavers have significant mental health problems. Prison leavers often have a history of trauma, ongoing substance misuse and housing insecurity. Only a minority of prison leavers receive mental health care on release from prison. Objectives The aim of the Engager research programme was to develop and evaluate a theory- and evidence-informed complex intervention designed to support individuals with common mental health problems (e.g. anxiety, depression) and other complex needs, including mental health comorbidity, before and after release from prison. Methods In phase 1, the intervention was developed through a set of realist-informed substudies, including a realist review of psychosocial care for individuals with complex needs, case studies within services demonstrating promising intervention features, focus groups with individuals from under-represented groups, a rapid realist review of the intervention implementation literature and a formative process evaluation of the prototype intervention. In a parallel randomised trial, methodological development included selecting outcome measures through reviewing literature, piloting measures and a consensus process, developing ways to quantify intervention receipt, piloting trial procedures and modelling economic outcomes. In phase 2, we conducted an individually randomised superiority trial of the Engager intervention, cost-effectiveness and cost–consequence analyses and an in-depth mixed-methods process evaluation. Patient and public involvement influenced the programme throughout, primarily through a Peer Researcher Group. Results In phase 1, the Engager intervention included multiple components. A practitioner offered participants practical support, emotional help (including mentalisation-based approaches) and liaison with other services in prison on the day of the participant’s release and for 3–5 months post release. An intervention delivery platform (i.e. training, manual, supervision) supported implementation. Outcome measures were selected through testing and stakeholder consensus to represent a broad range of domains, with a general mental health outcome as the primary measure for the trial. Procedures for recruitment and follow-up were tested and included flexible approaches to engagement and retention. In phase 2, the trial was conducted in three prison settings, with 280 participants randomised in a 1 : 1 ratio to receive either Engager plus usual care (n = 140) or usual care only (n = 140). We achieved a follow-up rate of 65% at 6 months post release from prison. We found no difference between the two groups for the Clinical Outcomes in Routine Evaluation – Outcome Measure at 6 months. No differences in secondary measures and sensitivity analyses were found beyond those expected by chance. The cost-effectiveness analysis showed that Engager cost significantly more at £2133 (95% of iterations between £997 and £3374) with no difference in quality-adjusted life-years (–0.017, 95% of iterations between –0.042 and 0.007). The mixed-methods process evaluation demonstrated implementation barriers. These barriers included problems with retention of the intervention team, and the adverse health and criminal justice system context. Seventy-seven per cent (108/140) of individuals had at least one community contact. Significant proportions of participants engaging received day release work and practical support. In contrast, there was evidence that the psychological components, mentalisation and developing a shared understanding were used less consistently. When engagement was positive, these components were associated with positive achievement of goals for individuals. We were also able to identify how to improve the intervention programme theory, including how to support individuals who were unrealistic in their perception of their ability to cope with challenges post release. Strengths and limitations Our development work provides a worked example of the development of a complex intervention, particularly given little prior evidence or theory specific to male offenders to build on. Our trial methodological development enabled the completion of, to the best of our knowledge, the first fully powered trial of a mental health intervention for prison leavers with common mental health problems. There were potential weaknesses in the trial methodology in terms of follow-up rates and outcome measures, with the latter potentially being insufficiently sensitive to important but highly individual changes in participants who responded to the intervention. Conclusions Delivering a randomised controlled trial for prison leavers with acceptable levels of follow-up is possible, despite adverse conditions. Full intervention implementation was challenging, but this is to be expected. Some individuals did respond well to the intervention when both practical and psychological support were flexibly deployed as intended, with evidence that most components were experienced as helpful for some individuals. It is recommended that several key components be developed further and tested, along with improved training and supervision, to support delivery of the Engager intervention within existing teams working with prison leavers. Trial registration This trial is registered as ISRCTN11707331. Funding This project was funded by the National Institute for Health and Care Research (NIHR) Programme Grants for Applied Research programme and will be published in full in Programme Grants for Applied Research; Vol. 10, No. 8. See the NIHR Journals Library website for further project information.