With the increasing demand for automated network systems in the Internet of Things (IoT), the models are becoming more complex and undergoing a tremendous change. Since the gadgets broadcast data wirelessly, they are easily targeted for attacks. Every day, thousands of attacks arise as a result of the addition of new protocols to the Internet of Things. This frequently makes the computing process more unreliable, ineffective and worse. The majority of these assaults are scaled-down versions of recognized cyberattacks from the past. This suggests that over time, even sophisticated systems like conventional systems will have trouble identifying even minute variations in attacks. However, Deep Learning (DL) has shown tremendous promise among attack detection techniques because of its early detection capability. Nevertheless, the efficacy of these DL methods is contingent upon the ability to gather vast amounts of labeled data from IoT sensors, requires more training time, and suffers from inaccuracies in detection. Hence, this research presents a modified activation function-based deep bidirectional long-short-term memory (Deep BiLSTM) model, which effectively captures the temporal dependencies and detect attacks effectively. Here, the modified activation function solves the vanishing gradient problem and high computational requirements. Specifically, the efficient features are extracted through the Ant-Chase optimization (AnChO), which assists in optimizing the BiLSTM model by tuning its parameters for attaining the best solution as well as to detect the attack in a precise manner with less computational time. Therefore, the accuracy, specificity, precision and recall of the proposed attack detection model attain the values of 96.46%, 97.40%, 97.91%, 95.05% and 97.465% correspondingly and the proposed system enhances IoT security by effectively detecting attacks.