In Southeast Asia, large-scale conversion of rainforest to oil palm plantations is one of the major causes of biodiversity declines. Recommendations for reducing species losses and increasing the sustainability of palm oil production advocate the retention of natural forest patches within plantations, but there is little evidence for the effectiveness of this strategy. Here, we examine to what extent rainforest remnants with different characteristics contribute to biodiversity within surrounding plantations. We sampled ground-dwelling ants in Sabah (Malaysian Borneo) using unbaited pit-fall traps along 1km transects spanning forest-plantation ecotones of 10 forest fragments (area 5ha–500ha) and two continuous forest sites which bordered plantations. Ant species richness in plantations varied according to richness in adjacent forest fragments, which increased with fragment size. A trend of declining species richness in plantations with distance from the forest ecotone was consistent with spillover of forest species into plantations adjacent to forest remnants. Ant assemblages in plantations also contained more carnivorous species adjacent to large forest fragments, suggesting large fragments may have benefits for pest control in plantations, as well as benefits for local biodiversity. Our results indicate that large forest fragments support distinctive ant assemblages and increase diversity within the planted area, but small fragments (<∼200ha) contribute little to plantation diversity. Thus retaining large fragments of forest may help mitigate the loss of species within oil palm plantations.