Nigeria entered its first technical recession since 2004 in the second quarter, marking a symbolic end to more than a decade of robust growth that turned the West African nation into the continent’s largest economy.

The 2.1% contraction in gross domestic product from a year earlier, reported by the country’s statistics authority Wednesday, follows a 0.4% annual decline in the first three months of the year, meeting the shorthand definition of a recession as two consecutive quarters of economic contraction. The most violent...