The Pentagon is replacing the top American commander in Afghanistan, Gen. David McKiernan, less than a year after he took over, marking a major overhaul in military leadership of a war that has presented President Obama with a worsening national security challenge.