After a long search, Libya’s transitional Parliament appeared to have finally selected a new prime minister on Sunday, choosing Ahmed Maitiq, a businessman, during a chaotic legislative session. But almost as soon as Mr. Maitiq was sworn in, lawmakers who said the vote had been conducted improperly challenged his appointment. As a result, it remained unclear whether the caretaker prime minister whom Mr. Maitiq was supposed to replace was willing to leave his post. The confusion was another blow to a transitional government that has struggled to find coherence since the fall of the dictator Col. Muammar el-Qaddafi in 2011. Parliament’s work has been undermined by internal squabbling and threatened by the country’s fractious militias, composed of men who fought Colonel Qaddafi during the uprising and were never disarmed.