The U.S. military says nearly two dozen militants were killed during a rare frontal attack on a U.S. base in southern Afghanistan .