American commandos flew into Somalia Tuesday and rescued two hostages who had been kidnapped by pirates based there, a mission ordered by President Barack Obama before he addressed the nation, the Pentagon said.