This article investigates the security ensured state estimation problem for cyber‐physical system via a data‐driven method. First, based on the fact that different packets possess varying a degree of significance, that is, some packets play more important roles in the state estimation than others, a novel stochastic important‐data‐based (IDB) attack mechanism is constructed from the attacker's perspective, which can focus on attacking the important packets thus is expected to achieve more destructiveness. Second, as a countermeasure to the proposed IDB attack, a new data‐driven compensation method is proposed, for the first attempt, to compensate for the attack effect and enhance the estimation quality. The designed defense strategy has the following two advantages: (1) only system input and output data are utilized to establish the novel estimator, without knowing the actual system model knowledge, and (2) by constructing a data‐driven output predictor to compensate for the data loss, the accuracy of the state estimation can be efficiently improved. With the aid of the least squares technique and completing square technique, a minimum upper bound matrix for the estimation error covariance is obtained by properly designing the estimator gain. Finally, an illustrative example is given to highlight the destructiveness of the designed stochastic IDB attack and the effectiveness of the proposed novel data‐based compensation method.