Background Given the novelty of gene replacement therapy with onasemnogene abeparvovec in spinal muscular atrophy, efficacy and safety data are limited, especially for children older than 24 months, those weighing more than 8·5 kg, and those who have received nusinersen. We aimed to provide real-world data on motor function and safety after gene replacement therapy in different patient subgroups.Methods We did a protocol-based, multicentre prospective observational study between Sept 21, 2019, and April 20, 2021, in 18 paediatric neuromuscular centres in Germany and Austria. All children with spinal muscular atrophy types 1 and 2 receiving onasemnogene abeparvovec were included in our cohort, and there were no specific exclusion criteria. Motor function was assessed at the time of gene replacement therapy and 6 months afterwards, using the Children’s Hospital of Philadelphia Infant Test of Neuromuscular Disorders (CHOP INTEND) and Hammersmith Functional Motor Scale-Expanded (HFMSE) scores. Additionally, in children pretreated with nusinersen, motor function was assessed before and after treatment switch. Off-target adverse events were analysed with a focus on liver function, thrombocytopaenia, and potential cardiotoxicity.Findings 76 children (58 pretreated with nusinersen and 18 who were nusinersen naive) with spinal muscular atrophy were treated with onasemnogene abeparvovec at a mean age of 16·8 months (range 0·8–59·0, IQR 9–23) and a mean weight of 9·1 kg (range 4·0–15·0, IQR 7·4–10·6). In 60 patients with available data, 49 had a significant improvement on the CHOP-INTEND score (≥4 points) and HFMSE score (≥3 points). Mean CHOP INTEND scores increased significantly in the 6 months after therapy in children younger than 8 months (n=16; mean change 13·8 [SD 8·5]; p<0·0001) and children aged between 8 and 24 months (n=34; 7·7 [SD 5·2]; p<0·0001), but not in children older than 24 months (n=6; 2·5 [SD 5·2]; p=1·00). In the 45 children pretreated with nusinersen and had available data, CHOP INTEND score increased by 8·8 points (p=0·0003) at 6 months after gene replacement therapy. No acute complications occurred during infusion of onasemnogene abeparvovec, but 56 (74%) patients had treatment-related side-effects. Serious adverse events occurred in eight (11%) children. Liver enzyme elevation significantly increased with age and weight at treatment. Six (8%) patients developed acute liver dysfunction. Other adverse events included pyrexia (n=47 [62%]), vomiting or loss of appetite (41 [54%]), and thrombocytopenia (n=59 [78%]). Prednisolone treatment was significantly prolonged with a mean duration of 15·7 weeks (IQR 9–19), mainly due to liver enzyme elevation. Cardiac adverse events were rare; only two patients had abnormal echocardiogram and echocardiography findings.Interpretation This study provides class IV evidence that children with spinal muscular atrophy aged 24 months or younger and patients pretreated with nusinersen significantly benefit from gene replacement therapy, but adverse events can be severe and need to be closely monitored.