SANA, Yemen — Yemen’s first new president in more than three decades was sworn in on Saturday, taking over a country with a broken economy, crumbling infrastructure, violent separatist movements, an active Qaeda franchise and Islamist militants in control of large swaths of territory.
After a year of antigovernment protests and rising insecurity in a country the United States sees as a critical ally in the fight against Al Qaeda, Yemenis were hopeful that the new government led by Abed Rabu Mansour Hadi, the former vice president, represented a fresh start.
But as if to underscore the problems Mr. Hadi faces, hours after he took the oath of office and promised to continue the war on Al Qaeda, militants attacked government targets in the southeastern port of Mukalla, killing at least 21 soldiers.
The swearing-in ceremony, in a room in Parliament packed with legislators, diplomats and journalists, was strikingly cheerful. Members of the former ruling party and the opposition, who fought bitterly over the past year, greeted one another with smiles, handshakes and kisses on the cheek.
When Mr. Hadi entered, the room burst into applause. He took the oath standing between two men who led enemy camps last year, Yahya al-Rayie, the Parliament speaker and a loyalist of former President Ali Abdullah Saleh, and Himyar al-Ahmar, whose tribesmen fought government forces on the streets of northern Sana.
“I know that there are complex and interlocking crises: economic, social and security,” Mr. Hadi afterward.
He called the fight against Al Qaeda “a national and religious duty.” And in an indirect reference to his predecessor, the autocratic Mr. Saleh, he urged officials from both sides to work together to “build a strong state through establishing institutions that are not based on a single personality.”
Mr. Hadi, 65, had been chosen as a consensus candidate by the former ruling party and the opposition, and was confirmed in a one-candidate election on Tuesday. The election was part of a United States-backed deal to end the political crisis and remove Mr. Saleh from office.
Despite the lack of choice, the turnout was heavy, said by the government to be 65 percent, suggesting that after more than a year of protests and unrest in which hundreds were killed, Yemenis were eager to embrace change.
“We consider this a historic day for Yemen,” said Ali al-Mamari, a legislator who quit Mr. Saleh’s party last spring after government supporters used violence against peaceful protesters. “All year there was a revolution, but now a new revolution started that is without weapons, without conflict, to transform our country into a civil state. I am incredibly happy.”
The challenges remaining, however, are immense.
“This transfer of presidential power is historic for Yemen,” said April Alley, a regional analyst for the International Crisis Group. “But it’s the days ahead that are going to really matter.
“There are the economic and security challenges that are immediate,” she said. “And also there are political challenges when it comes to pulling the country back together, dealing with the separatist movement in the south and a different set of grievances with the Houthis,” rebels who control Saada Province in the north.
The United States, which sees Yemen largely through the lens of counterterrorism, is expected to be involved in restructuring the military into what it hopes will be a more effective force against Al Qaeda. President Obama’s chief counterterrorism adviser, John O. Brennan, raised those concerns in private meetings with Mr. Hadi in Sana last week.
Even the accomplishment being celebrated on Saturday, the end of Mr. Saleh’s 33-year rule, was tempered by the reality that he still wields considerable influence. His relatives control most of the military and government security agencies, and it is not known how independent Mr. Hadi, a longtime Saleh loyalist, will be.
Mr. Saleh kept a low profile on Saturday and, despite having promised to hand over power formally to Mr. Hadi, did not attend the ceremony. He had been in the United States for medical treatment for injuries sustained in an attack on his presidential palace last June, and returned to Yemen early Saturday. He “returned to his private residence in Sana, not the presidential palace,” said Mohammed Albasha, a spokesman for the Yemeni Embassy in Washington, without elaborating.