I've reworked the circuit to put a low-pass RC filter between the phototransistor and the mbed analog input:
and the spikes are now gone:
There's a bit of noise on the flat section at the end where the meter had stopped, but that may only be visible now because the range of values is significantly reduced. Previously, ignoring the spikes, the values ranged from about 4000 to 40000, but now I'm only getting 3100 to 4250.
I'm not sure how to adjust the resistor and capacitor values to increase the range, and it doesn't help that I don't know what's inside the mbed on that analog pin.