thumb|Drawing of the archetypical ninja from a series of [[Hokusai Manga|sketches by Hokusai. Woodblock print on paper. Vol. six, 1817.]]

A ,

thumb|The ruins of [[Hara Castle]]

Suspecting that the castle's supplies might be running low, the siege commander Matsudaira Nobutsuna ordered a raid on the castle's provisions. Here, the Kōga captured bags of enemy provisions, and infiltrated the castle by night, obtaining secret passwords. Days later, Nobutsuna ordered an intelligence gathering mission to determine the castle's supplies. Several Kōga ninja—some apparently descended from those involved in the 1562 assault on an Imagawa clan castle—volunteered despite being warned that chances of survival were slim. A volley of shots was fired into the sky, causing the defenders to extinguish the castle lights in preparation. Under the cloak of darkness, ninja disguised as defenders infiltrated the castle, capturing a banner of the Christian cross. The Ukai diary writes,

As the siege went on, the extreme shortage of food later reduced the defenders to eating moss and grass. This desperation would mount to futile charges by the rebels, where they were eventually defeated by the shogunate army. The Kōga would later take part in conquering the castle:

With the fall of Hara Castle, the Shimabara Rebellion came to an end, and Christianity in Japan was forced underground. These written accounts are the last mention of ninja in war.

Edo period

After the Shimabara Rebellion, there were almost no major wars or battles until the bakumatsu era. To earn a living, ninja had to be employed by the governments of their Han (domain), or change their profession. Many lords still hired ninja, not for battle but as bodyguards or spies. Their duties included spying on other domains, guarding the daimyō, and fire patrol. A few domains like Tsu, Hirosaki and Saga continued to employ their own ninja into the bakumatsu era, although their precise numbers are unknown.

Many former ninja were employed as security guards by the Tokugawa shogunate, though the role of espionage was transferred to newly created organizations like the onmitsu and the oniwaban. Others used their ninjutsu knowledge to become doctors, medicine sellers, merchants, martial artists, and fireworks manufacturers. Some unemployed ninja were reduced to banditry, such as Fūma Kotarō and Ishikawa Goemon.

{| class="wikitable sortable"

|-

| colspan="2" | Ninja employed in each domain, Edo period

|-

! Han (domain)

! Number of ninja

|-

|Kishū Domain

|200+

|-

|Kishiwada Domain

|50

|-

|Kawagoe Domain

|50

|-

|Matsue Domain

|30

|-

|Hirosaki Domain

|20

|-

|Fukui Domain

|12

|-

|Hikone Domain

|10

|-

|Okayama Domain

|10

|-

|Akō Domain

|5

|}

Ninja stereotypes in theatre