The invention relates to a method for producing a microelectromechanical device (1) comprising a functional unit (2), a cavity (3), and a cap structure (4) that covers the cavity (3) and has at least one cavity access (5), in which method the cap structure (4) is produced by sequentially depositing material
layers on a cap substrate (6), the functional unit (2) is attached to the cap structure (4), and at least one
inlet channel (7) in the at least one cavity access (5) is formed in the cap structure (4) by means of
etching, wherein, during the production of the cap structure (4), at least one
inlet channel (7), at least one outlet channel (9) opening into the cavity (3), and at least one lateral channel (8) running parallel to a surface of the cap substrate (6) and opening into the at least one
inlet channel (7) and into the at least one outlet channel (9) are formed in the cap structure (4), and wherein, during the production of the cap structure (4), a first etch-stop structure (10a) is formed in order to limit the
insertion depth of the inlet channel (7) into the cap structure (4). The invention also relates to a microelectromechanical device (1).