A gas sensor for measuring the amount of a to-be-measured gas component in a to-be-measured gas present in an external space, which comprises: a solid electrolyte which is in contact with an external space, an internal space formed inside the solid electrolyte, a first diffusion resistance portion and a second diffusion resistance portion for introducing a to-be-measured gas from the external space via a gas inlet, at a given diffusion resistance, a pumping means which has an inner pumping electrode formed inside the internal space and an outer pumping electrode formed outside the internal space and which subjects the oxygen contained in the to-be-measured gas introduced from the external space, to a pumping treatment based on a controlling voltage applied between the two electrodes (40, 42), a gas component-measuring means having a detection electrode, which electrode is capable of decomposing a to-be-measured gas component contained in the to-be-measured gas after the pumping treatment by the pumping means and measures the to-be-measured gas component contained in the to-be-measured gas, based on the oxygen generated by the decomposition, a porous protective layer for detection electrode, which is formed so as to cover the detection electrode of the gas component-measuring means, and two harmful substance-trapping layers made of a porous material capable of trapping a harmful substance, which are formed apart from and upstream of the detection electrode in a gas passage formed inside the solid electrolyte so as to allow the flowing of the to-be-measured gas; wherein one of the harmful substance-trapping layers is formed on the upper surface of the gas passage and the other of the harmful substance-trapping layers is formed on the lower surface of the gas passage between the gas inlet and the first diffusion resistance portion and/or between the first and second diffusion resistance portions. a solid electrolyte which is in contact with an external space, an internal space formed inside the solid electrolyte, a first diffusion resistance portion and a second diffusion resistance portion for introducing a to-be-measured gas from the external space via a gas inlet, at a given diffusion resistance, a pumping means which has an inner pumping electrode formed inside the internal space and an outer pumping electrode formed outside the internal space and which subjects the oxygen contained in the to-be-measured gas introduced from the external space, to a pumping treatment based on a controlling voltage applied between the two electrodes (40, 42), a gas component-measuring means having a detection electrode, which electrode is capable of decomposing a to-be-measured gas component contained in the to-be-measured gas after the pumping treatment by the pumping means and measures the to-be-measured gas component contained in the to-be-measured gas, based on the oxygen generated by the decomposition, a porous protective layer for detection electrode, which is formed so as to cover the detection electrode of the gas component-measuring means, and two harmful substance-trapping layers made of a porous material capable of trapping a harmful substance, which are formed apart from and upstream of the detection electrode in a gas passage formed inside the solid electrolyte so as to allow the flowing of the to-be-measured gas; wherein one of the harmful substance-trapping layers is formed on the upper surface of the gas passage and the other of the harmful substance-trapping layers is formed on the lower surface of the gas passage between the gas inlet and the first diffusion resistance portion and/or between the first and second diffusion resistance portions.