An influx of money in the last weeks of the campaign, totaling about $20 million, seemed to have an effect, as did Mr. Johnson’s attempt to soften his image with television ads portraying him hugging constituents and changing a diaper.