BUFFALO — At his cubicle at the State Transportation Department building here, Mohamed Abdullahi Mohamed recounted what he did during a recent leave of absence. He trimmed the size of the federal government. He instituted regular paychecks for the military. He campaigned against corruption. And he avoided being shot.

“Every morning when I was brushing my teeth I heard bullets hitting the metal over my window,” Mr. Mohamed said. “It was like, pop pop pop pop. The first day I was shocked. But after that I knew the bullets would not get through, so I continued brushing.”

Mr. Mohamed, 49, smiled genially over the neutral-toned cubicle dividers and file cabinets of the state office building. For eight months, starting last November, he was the prime minister of his native country, Somalia, one of the most chaotic nations on earth. And then, as suddenly as he had left, he was back in his cubicle at the Transportation Department, where he makes sure the department’s contracts and contractors comply with nondiscrimination and affirmative action requirements.

“This is my life,” he said.

Mr. Mohamed, who has lived in the United States since 1985, said he had no plan to join the Somali government when friends helped him arrange a meeting with the country’s president, Sheik Sharif Sheik Ahmed, in September 2010 during a meeting of the United Nations General Assembly in New York. Mr. Mohamed said he talked to the president about how factions in government might cooperate, drawing on his own experience working with difficult contractors in Erie County. At the time, the president had just dismissed his previous prime minister.