YAP is a mechanosensitive transcriptional activator with a critical role in cancer, regeneration, and organ size control. Here, we show that force applied to the nucleus directly drives YAP nuclear translocation by decreasing the mechanical restriction of nuclear pores to molecular transport. Exposure to a stiff environment leads cells to establish a mechanical connection between the nucleus and the cytoskeleton, allowing forces exerted through focal adhesions to reach the nucleus. Force transmission then leads to nuclear flattening, which stretches nuclear pores, reduces their mechanical resistance to molecular transport, and increases YAP nuclear import. The restriction to transport is further regulated by the mechanical stability of the transported protein, which determines both active nuclear transport of YAP and passive transport of small proteins. Our results unveil a mechanosensing mechanism mediated directly by nuclear pores, demonstrated for YAP but with potential general applicability in transcriptional regulation.