STOCKHOLM—The Lego man won’t be filling up at the Shell station much longer.

Lego A/S, the Danish toy-brick maker, said on Wednesday it would end its decadeslong, co-branding relationship with oil giant Royal Dutch Shell PLC, amid pressure from environmental group Greenpeace, which targeted the deal in a popular online video and petition.

Since...