How do microcontroller interrupts work?
This is a pretty general question.  There is a lot more detail involved than this general answer and many ways to achieve it.

A processor is essential a set of registers executing a program.  When an interrupt occurs, the processor interrupts the present program flow and executes an interrupt service routine.  

The first instructions of the ISR push the present contents of registers on the stack.  

The middle of the ISR is where the context switches and the registers are used for a new purpose.  In executing these instructions, the interrupt should be cleared.

The last instructions pop the old registers off the stack.  When the registers are popped, the processor continues with original code, with no knowledge that the ISR was serviced.