Illegal exploitation of resources is a cause of environmental degradation worldwide. The effectiveness of conservation initiatives such as marine protected areas relies on users' compliance with regulations. Although compliance can be motivated by social norms (e.g. peer pressure and legitimacy), some enforcement is commonly necessary. Enforcement is expensive, particularly in areas far from land, but costs can be reduced by optimizing enforcement. We present a case study of how enforcement could be optimized at Cocos Island National Park, Costa Rica, an offshore protected area and World Heritage Site. By analysing patrol records we determined the spatial and temporal distribution of illegal fishing and its relationship to patrol effort. Illegal fishing was concentrated on a seamount within the Park and peaked during the third year-quarter, probably as a result of oceanographic conditions. The lunar cycle in conjunction with the time of year significantly influenced the occurrence of incursions. The predictability of illegal fishing in space and time facilitates the optimization of patrol effort. Repeat offenders are common in the Park and we suggest that unenforced regulations and weak governance are partly to blame. We provide recommendations for efficient distribution of patrol effort in space and time, establishing adequate governance and policy, and designing marine protected areas to improve compliance. Our methods and recommendations are applicable to other protected areas and managed natural resources.