A microelectromechanical device comprising: a substrate (21; 121) of semiconductor material; a first structural layer (23; 53; 123) of semiconductor material on the substrate (21; 121); a second structural layer (25; 55; 90; 125) of semiconductor material on the first structural layer (23; 53; 123): a sensing mass (32; 132), coupled to the substrate (21; 121) by first elastic connections (35; 135), which are configured to enable the sensing mass (32; 132) to oscillate in a sensing direction perpendicular to the substrate (21; 121), with a maximum elongation with respect to a resting position; an out-of-plane stopper structure (38; 57; 97; 138) comprising a stopper anchorage (39; 59; 139) fixed to the substrate (21; 121) and a mechanical end-of-travel structure (40; 60; 98; 140); and a cap, joined to the second structural layer through an adhesion layer; wherein the mechanical end-of-travel structure (40; 60; 98; 140) faces the sensing mass (32; 132), and is separated from the sensing mass (32; 132) by a gap (41; 61) having a width (W; W'; W") smaller than the maximum elongation; characterized in that the sensing mass (32; 132)extends in the first structural layer (23; 53; 123) and the mechanical end-of-travel structure (40; 60; 98; 140) extends in the second structural layer (25; 55; 90; 125) and is coupled to the stopper anchorage (39; 59; 139) by second elastic connections (42; 62; 142) configured to enable displacements of the mechanical end-of-travel structure (40; 60; 98; 140) with respect to the sensing direction in response to an impact of the sensing mass (32; 132). a substrate (21; 121) of semiconductor material; a first structural layer (23; 53; 123) of semiconductor material on the substrate (21; 121); a second structural layer (25; 55; 90; 125) of semiconductor material on the first structural layer (23; 53; 123): a sensing mass (32; 132), coupled to the substrate (21; 121) by first elastic connections (35; 135), which are configured to enable the sensing mass (32; 132) to oscillate in a sensing direction perpendicular to the substrate (21; 121), with a maximum elongation with respect to a resting position; an out-of-plane stopper structure (38; 57; 97; 138) comprising a stopper anchorage (39; 59; 139) fixed to the substrate (21; 121) and a mechanical end-of-travel structure (40; 60; 98; 140); and a cap, joined to the second structural layer through an adhesion layer; wherein the mechanical end-of-travel structure (40; 60; 98; 140) faces the sensing mass (32; 132), and is separated from the sensing mass (32; 132) by a gap (41; 61) having a width (W; W'; W") smaller than the maximum elongation; characterized in that the sensing mass (32; 132)extends in the first structural layer (23; 53; 123) and the mechanical end-of-travel structure (40; 60; 98; 140) extends in the second structural layer (25; 55; 90; 125) and is coupled to the stopper anchorage (39; 59; 139) by second elastic connections (42; 62; 142) configured to enable displacements of the mechanical end-of-travel structure (40; 60; 98; 140) with respect to the sensing direction in response to an impact of the sensing mass (32; 132). a sensing mass (32; 132), coupled to the substrate (21; 121) by first elastic connections (35; 135), which are configured to enable the sensing mass (32; 132) to oscillate in a sensing direction perpendicular to the substrate (21; 121), with a maximum elongation with respect to a resting position; an out-of-plane stopper structure (38; 57; 97; 138) comprising a stopper anchorage (39; 59; 139) fixed to the substrate (21; 121) and a mechanical end-of-travel structure (40; 60; 98; 140); and a cap, joined to the second structural layer through an adhesion layer; wherein the mechanical end-of-travel structure (40; 60; 98; 140) faces the sensing mass (32; 132), and is separated from the sensing mass (32; 132) by a gap (41; 61) having a width (W; W'; W") smaller than the maximum elongation; characterized in that the sensing mass (32; 132)extends in the first structural layer (23; 53; 123) and the mechanical end-of-travel structure (40; 60; 98; 140) extends in the second structural layer (25; 55; 90; 125) and is coupled to the stopper anchorage (39; 59; 139) by second elastic connections (42; 62; 142) configured to enable displacements of the mechanical end-of-travel structure (40; 60; 98; 140) with respect to the sensing direction in response to an impact of the sensing mass (32; 132).