A gas sensor comprising: a gas detection element (8,9); a ceramic wiring substrate on which the gas detection element (8,9) is mounted; and a protective cap (3,103), which is attached to the ceramic wiring substrate in such a manner as to cover the gas detection element (8,9) and which is made of metal, defines, when attached to the ceramic wiring substrate, a gas-measuring space in cooperation with the ceramic wiring substrate, and has a gas intake (31 to 39) for introducing gas to be measured into the gas-measuring space from the outside thereof, wherein the ceramic wiring substrate has a multilayer structure in which a plurality of ceramic dielectric layers (4,5,6,7) are laminated, the ceramic wiring substrate further comprises a recess (4A, 4B) and a cavity, the recess (4A,4B) is formed on a portion of a side surface of the ceramic wiring substrate which corresponds to a side surface of a ceramic dielectric layer other than an uppermost ceramic dielectric layer which forms a top surface of the ceramic wiring substrate, the cavity is formed on the top surface of the ceramic wiring substrate, the gas detection element (8, 9) is mounted in the cavity, the protective cap comprises a ceiling portion, which has the gas intake, and a perpendicularly projecting portion (41,42) extending downward from the side edge of the ceiling portion and extending along the side surface of the ceramic wiring substrate, and an engagement projection (41A, 42A) to be fitted into the recess (4A, 4B) is formed on the perpendicularly projecting portion (41,42); the back surface of the ceiling portion abuts on the upper surface of the ceramic wiring substrate, and the protective cap is held on the ceramic wiring substrate in a non-adhering condition. a gas detection element (8,9); a ceramic wiring substrate on which the gas detection element (8,9) is mounted; and a protective cap (3,103), which is attached to the ceramic wiring substrate in such a manner as to cover the gas detection element (8,9) and which is made of metal, defines, when attached to the ceramic wiring substrate, a gas-measuring space in cooperation with the ceramic wiring substrate, and has a gas intake (31 to 39) for introducing gas to be measured into the gas-measuring space from the outside thereof, wherein the ceramic wiring substrate has a multilayer structure in which a plurality of ceramic dielectric layers (4,5,6,7) are laminated, the ceramic wiring substrate further comprises a recess (4A, 4B) and a cavity, the recess (4A,4B) is formed on a portion of a side surface of the ceramic wiring substrate which corresponds to a side surface of a ceramic dielectric layer other than an uppermost ceramic dielectric layer which forms a top surface of the ceramic wiring substrate, the cavity is formed on the top surface of the ceramic wiring substrate, the gas detection element (8, 9) is mounted in the cavity, the protective cap comprises a ceiling portion, which has the gas intake, and a perpendicularly projecting portion (41,42) extending downward from the side edge of the ceiling portion and extending along the side surface of the ceramic wiring substrate, and an engagement projection (41A, 42A) to be fitted into the recess (4A, 4B) is formed on the perpendicularly projecting portion (41,42); the back surface of the ceiling portion abuts on the upper surface of the ceramic wiring substrate, and the protective cap is held on the ceramic wiring substrate in a non-adhering condition.