Metal–organic frameworks (MOFs) offer disruptive potential in micro- and optoelectronics because of the unique properties of these microporous materials. Nanoscale patterning is a fundamental step in the implementation of MOFs in miniaturized solid-state devices. Conventional MOF patterning methods suffer from low resolution and poorly defined pattern edges. Here, we demonstrate the resist-free, direct X-ray and electron-beam lithography of MOFs. This process avoids etching damage and contamination and leaves the porosity and crystallinity of the patterned MOFs intact. The resulting high-quality patterns have excellent sub-50-nm resolution, and approach the mesopore regime. The compatibility of X-ray and electron-beam lithography with existing micro- and nanofabrication processes will facilitate the integration of MOFs in miniaturized devices.