A search for physics beyond the standard model (SM) in final states with an electron or muon and missing transverse momentum is presented. The analysis uses data from proton-proton collisions at a centre-of-mass energy of 13 TeV, collected with the CMS detector at the LHC in 2016-2018 and corresponding to an integrated luminosity of 138 fb(-1). No significant deviation from the SM prediction is observed. Model-independent limits are set on the production cross section of W' bosons decaying into lepton-plus-neutrino final states. Within the framework of the sequential standard model, with the combined results from the electron and muon decay channels a W' boson with mass less than 5.7 TeV is excluded at 95% confidence level. Results on a SM precision test, the determination of the oblique electroweak W parameter, are presented using LHC data for the first time. These results together with those from the direct W' resonance search are used to extend existing constraints on composite Higgs scenarios. This is the first experimental exclusion on compositeness parameters using results from LHC data other than Higgs boson measurements.