LONDON—The U.K. economy slowed sharply in the first quarter as consumers pared back spending, a warning sign on growth ahead of a national election in June and the start of Britain’s exit talks with the European Union.

The British economy expanded at a quarterly rate of 0.3% in the first quarter of 2017, the U.K.’s Office for National Statistics said Friday, less than half the speed of the 0.7% expansion recorded in the final three months of last year. It was the weakest quarterly expansion since the first quarter of 2016,...