The career Marine was respected among allies and adversaries and on Capitol Hill, and he was beloved in the Pentagon as a protector against a president with scant understanding of his own role as commander in chief.