Mechanism of superconductivity in the Hubbard model at intermediate interaction strength