Janet Napolitano has a message for the next head of the Department of Homeland Security: “You will need a large bottle of Advil.”

In a farewell speech Tuesday, Napolitano gave a wide-ranging defense of her 4 1/2 years as head of one of the government’s youngest and most unwieldy departments.

“Some have said that being the secretary of DHS is the most thankless job in Washington,” Napolitano said at the National Press Club in the capital. “That’s not true. No doubt it is a very big and complex job. It is literally a 24/7 job,” she said. “Yet, as my successor will soon learn, it is also one of the most rewarding jobs there is. What you do here matters to the lives of people all across our great nation, and your decisions affect them in direct, tangible ways,” she said.

Cobbled together from 22 disparate agencies and departments after the Sept. 11, 2001, attacks, under Napolitano’s watch the 240,000-person department responded to disasters as diverse as the H1N1 flu pandemic, the Deepwater Horizon oil spill, Hurricane Sandy, and devastating tornadoes that touched down in Joplin, Mo.; Tuscaloosa, Ala.; and Moore, Okla.

Napolitano presided over a near doubling of border patrol agents and a drop in illegal border crossings to the lowest level in decades. She ramped up the deportation of convicted criminals and allowed immigrants brought to the country illegally as children to apply for provisional legal status and work permits.

The nation experienced one major terrorist strike during her tenure when two pressure cooker bombs exploded April 15 at the finish line of the Boston Marathon, killing three people and injuring more than 260. Napolitano said the attack was a “despicable act of violence directed at a peaceful sporting event.”

But she said that the emergency response to the marathon attack “saved lives” and was the product of years of training and federal investment in improving how local law enforcement and first responders react to disasters.

Napolitano said the most important take-away from her time there was that the department must be “flexible and agile” and learn from mistakes.

“Being flexible and agile means acknowledging that we may not be able to stop all threats all the time,” Napolitano said, “but we can — and must — be prepared to address them quickly when they happen, minimize their consequences, draw pragmatic lessons, and emerge stronger and better.”

Two other terrorist plots that unfolded on her watch involved bombs that failed to explode and could have been deadly. A Nigerian man was able to board Northwest Airlines flight to Detroit on Christmas Day 2009 with a bomb in his underwear and a recently naturalized Pakistani-American man attempted to set off a large car bomb in Times Square in May 2010.

After the Detroit case, Napolitano was criticized for saying “the system worked.” Napolitano apologized later, and she pushed for increased passenger screening and more sharing of terrorism data on foreigners applying for visas.

After an al-Qaida cell in Yemen hid explosives in printer cartridges shipped to the U.S. in 2010, Napolitano worked with other countries to increase screening of air cargo, she said.

President Barack Obama has not named a replacement for Napolitano. The current director of U.S. Citizenship and Immigration Services, Alejandro Mayorkas, was expected to step in as the acting director, but his nomination for deputy secretary has been delayed by a DHS Inspector General’s Office investigation into whether he wrongly helped a business secure visas for foreign investors.

Officials said New York Police Commissioner Raymond Kelley, retired Coast Guard Adm. Thad Allen and former Washington Gov. Chris Gregoire are among those who have been considered for the post.