Detecting near out-of-distribution (OOD) data is important when deploying a deep learning model. The goal of near-OOD detection is to distinguish the OOD samples when distributions of inliers and outliers are similar. However, an input sample containing unexpected information may degrade the OOD detection performance in downstream tasks. To address this problem, we propose an algorithm called attention masking, which masks the less-attended parts of the given input to precisely calculate its Mahalanobis distance from the training distribution. In our experiments, we use a largescale pre-trained model to measure the performance of our approach on the vision OOD benchmark tasks. For instance, on CFAR-100vs. CIFAR-10 detection, we improve the AUROC of Mahalanobis distance-based OOD detection from 91.23% to 92.89% using ViT-Base model. In addition, we measured the performance of the challenging zero-shot OOD detection, which only utilizes the pre-trained weights without fine-tuning on CFAR-100 or CFAR-10, and achieved an average AUROC improvement of 7% on CFAR-100vs. CFAR-10 detection.