WASHINGTON — Janet Napolitano, the secretary of homeland security, announced Friday that she was stepping down, setting off a search to fill one of the most challenging positions in government at a time when the Obama administration is struggling to get a team in place for the president’s second term.

Ms. Napolitano, a former Arizona governor who for four and a half years shaped the administration’s response to hurricanes, terrorist attacks, illegal immigration and a catastrophic oil spill, will leave in September to become president of the University of California system. Ms. Napolitano had her eye on becoming the next attorney general, but now is taking herself out of the Washington arena.

Her departure deprives the administration of one of its most prominent voices on immigration even as it is in the throes of pushing Congress for an overhaul that would provide a pathway to citizenship for most of the 11 million foreigners who are here illegally. Ms. Napolitano said she decided to leave only after concluding that her absence would not affect chances for the immigration legislation, a person close to her said, but confirmation of a successor could become wrapped up in the larger immigration debate.

Her move west creates an opening that could be hard for President Obama to fill. The secretary of homeland security presides over a sprawling department that was created after the attacks of Sept. 11, 2001, by combining nearly two dozen agencies as varied as the Secret Service, the Transportation Security Administration, the Coast Guard and the Federal Emergency Management Agency.