AVR port transient characteristics
I'll show you how to see this for yourself:







simulate this circuit &ndash; Schematic created using CircuitLab

That's a simplified behavioral diagram of the output pin. It's actually more complicated. But for these illustrative purposes, it's fine.

The output pin may be tied "HI" by turning \$M_1\$ ON and turning \$M_2\$ OFF. The output pin may be tied "LO" by turning \$M_1\$ OFF and turning \$M_2\$ ON.

If you place this into LTspice (and replaced that "square wave" thingy with an actual voltage source using rise and fall times close to \$1\:\text{ns}\$ or \$2\:\text{ns}\$, you'll see your spikes. Nice and pretty.

Your MCU is trying to drive the output quite quickly between two opposing values. But there is some capacitance between the output pin and the gates present within the driver circuitry. This is inescapable. It's a fundamental property of a MOSFET. I've added some capacitance here to exaggerate the details and make that visible to you. But it is there whether or not I add them to the circuit, explicitly.

When the MCU attempts to change the output, it does this by very rapidly changing the drive voltages to these gates. But the capacitors have some voltage across them that doesn't immediately vanish. It takes a moment to discharge. So for a very fast moment, their voltage "pushes" the pin further than expected (above the upper rail or below the lower rail.) Once that happens, a little time must also pass as these capacitors re-establish a new stable value. This is done through some resistance present. So you will see a sharp edge (the rate of change of which tells you a lot about how fast the internal drive circuitry can "move"), followed by a slightly more gradual relaxation as the capacitors regain a new balance. Your captured images show this behavior quite well.