In the rapidly evolving domain of the Internet of Things (IoT) and fog computing, maintaining security, scalability, and efficient operation poses significant challenges. Addressing these issues, this study introduces "BlockFog," a novel blockchain-based framework designed to bolster intrusion defense in IoT fog computing environments. The core objective of BlockFog is to counteract the vulnerabilities inherent in decentralized IoT ecosystems by leveraging blockchain technology for enhanced security and transparency. The framework's innovative design integrates crucial components such as Device Onboarding & Identity Management, Data Integrity & Logging, Smart Contract-Driven Intrusion Detection, Automated Blockchain Responses, Secure Peer-to-Peer Communication, and a Lightweight Consensus Mechanism. These elements work collectively to ensure the security and functionality of IoT devices within the fog computing paradigm. BlockFog stands out for its meticulous approach to handling high transaction volumes with off-chain computations and layer-2 solutions, ensuring data integrity and facilitating seamless audit processes. The framework's resilience is further demonstrated through its robust response to evolving cyber threats, incorporating Over-the-Air (OTA) updates and advanced data protection mechanisms like zero-knowledge proofs. A comparative analysis highlights BlockFog's superior performance against existing models. The results reveal BlockFog's lower latency rates in normal, high traffic, and attack scenarios, its higher throughput efficiency, and its more effective resource utilization in terms of CPU, memory, and bandwidth usage. Moreover, BlockFog exhibits an enhanced ability to detect and respond to malicious activities, including DDoS attacks, with significantly higher accuracy than its counterparts. These findings underscore BlockFog's potential in redefining security and operational paradigms in IoT fog computing, making it a robust, agile, and transparent framework suitable for the current digital landscape.