The temple was built in 1585 as a prayer place of the Kaga Domain by Lord Maeda Toshiie, the founder of the Kaga Domain. Originally it was situated near Kanazawa Castle, but in 1643, Toshitsune Maeda, the third lord of the Kaga Domain, moved the temple to the Tera-machi district to the south of the castle. In preparation for an emergency attack of the central government (Tokugawa shogunate), the Maeda family considered the temples in Tera-machi as a shield.
Since the shogun imposed strict building restrictions as one way of weakening his regional lords, Myōryū-ji was designed to circumvent the restrictions and serve as a disguised military outpost. It was supplemented with considerable defences and escape routes, so that its defenders could alert the castle in the event of an attack. The temple's defences aimed to guard against intruders or attack, and include hidden tunnels, secret rooms, traps, and a labyrinth of corridors and staircases.
In the Edo period, the Tokugawa shogunate prohibited the construction of buildings higher than three stories. Viewed from the outside, the temple appears to be a two-story building, but actually it is a four-story building with seven-layer internal structure.
Myōryū-ji is better known as Ninja-dera. While not actually associated with ninjas, the temple earned its nickname because of its many deceptive defences.
The temple is built around a central well which is approximately 25 m deep; the bottom of the well is said to connect to a tunnel to Kanazawa Castle. This building has a complicated structure which includes a middle floor and middle-middle floor, and contains 23 rooms and 29 staircases. There are different contrivances to fool the enemy such as hidden chambers and stairs, completely unexpected and reversible trap like doors and floors, secret tunnels, escape pits. The lookout on the top affords a view of the surrounding area. In addition, the temple is very strong and durable enough to withstand typhoons and heavy snow.