The nilgai (Boselaphus tragocamelus) is a widespread species in India that forages in forest as well as on agricultural lands. In Tadoba-Andhari Tiger Reserve, India, it typically takes to crop-raiding at night, while it rests and forages in forest during the daytime. We studied changes in herding and vigilance behaviour during foraging in forest versus in agricultural lands and monsoon versus post-monsoon in the years 2012–2015. We recorded number of individuals (herd size), sex-age composition and number of individuals per unit area of herd's spread (compactness) for every herd under observation using instantaneous scan sampling in forest (176 herds) and farms (321 herds), while spatial trends in herd size on agricultural lands were studied using transect sampling at night. Vigilance behaviour was studied using focal-animal sampling in forest (n = 91) and farms (n = 52) by choosing a single individual per herd under 15 min of observation. Herd sizes were significantly larger in forest (monsoon, median = 3, interquartile range (IQR) = 2–6, post-monsoon, median = 5, IQR = 3–8) than on farms adjacent to forest (monsoon = 3, IQR = 1–5, post-monsoon = 4, IQR = 2–5) and further decreased non-linearly with distance from the forest edge. Herds were more compact, i.e. with smaller inter-individual distance in forests than on farms. Crop-raiding was found to be female-biased, and adult males as well as newborn calves were observed on agricultural lands significantly less frequently. The median vigilance frequency was significantly higher on farms (1.4 min−1) as compared with forests (0.205 min−1) but the median unit scan duration was significantly less in farms (6 s) compared with forest (60 s). The observed differences are likely to be due to difference in the nature of risk faced in the two habitats. In forest, detection of ambush predators such as tigers that occur at a low density, requires careful watch and larger herds increase the chances of detection. In contrast, detection of guarding farmers on agricultural lands who are present at a higher density and make their presence conspicuous to drive away crop raiders would need a glance of smaller time duration. As crop-raiding occurs at night, moonlight is likely to affect the frequency of crop-raiding but we did not find evidence for any deterrent effect of moonlight on the frequency of crop-raiding. The data suggest that the nilgai exhibits substantial behavioural plasticity in response to different nature and levels of risks faced in the two habitats.