Basic answer
MRI machines work by permeating human tissue with powerful magnetic fields that cause protons to release energy that the machines then detect. The machines can distinguish between body parts by inferring how long each section of the body took for their protons to release this energy.
I don't often include basic answers in my articles, but I thought I may as well for this one, since I assume a lot of people might be reading up about MRI's purely because they've got one scheduled, and just want to know the gist of it out of comfort - which is fair enough!
With that aside though, here's the more interesting version...

MRI machines exploit a mechanism that we call super-conduction. It's fairly straight-forward to understand, and I've written a separate article that goes into depth on it here, but it briefly goes like this:
The lower the temperature, the less particles move or vibrate, which reduces their interference with passing electrons.
As more electrons are able to pass without being obstructed, a higher current can be achieved and as you get closer to absolute zero (-273 degrees Celsius), the particles begin to barely vibrate/move at all, meaning that electrons can flow through with such ease that a huge current can be achieved.
We call this interaction at extremely low temperatures super-conduction, and with a higher current, a stronger magnetic field is achieved.
MRI machines reach these absurdly low temperatures through being filled with liquid helium, which, in order to remain a liquid and not boil away into a gas, needs to be cooled to -270 degrees Celsius! That's dangerously close to the forbidden Absolute Zero, which you can read all about here.
When an electrical current is achieved through the machine (simply by turning the power on), an extremely powerful magnetic field permeates the tissue of the patient. If you've ever been in one before, you'll know that they always ask you to remove anything metal from your person if you're going into one of these MRI machines, as the magnetic field would violently strip it away from you, potentially causing some form of harm to you and the machine.
So a magnetic field permeates your body... But how does this allow images of your tissue to be taken?
You're made of atoms (but mostly empty space!), and every atom in your body contains 1 or several protons, which are positively charged subatomic particles. Given their charge, they interact with this magnetic field, specifically they align with it.
Side note - if you're interested in knowing how on Earth you could possibly be mostly empty space, then check out this article!
If you've ever studied quantum mechanics at all, then you'll know that 1 property of a subatomic particle that's overlooked elsewhere in say the foundational physics that we get taught at school, is spin.
When you're learning about electrons and protons at school, nobody ever really tells you that they spin at all - you just learn that they have mass and a charge associated with them.
Protons can spin in either direction and the axis of which they rotate is random, but when they're contained in a strong enough magnetic field, they'll be forced to align with the direction of the magnetic field lines.
Now, something that I want to clarify here is that when physicists describe quantum particles as "spinning", do not take this literally.
The term "spin" can be broken down into two different parts:
Rotational momentum and;
Angular momentum
Rotational momentum involves the axis of rotation lying inside of the particle at question, and it's what we would most commonly associate with the term "spin".
In the case of quantum particles though, such as protons and electrons, it's the angular momentum that we're describing when we say that they're spinning - when the axis of rotation is outside of the particle.
They're not rotating like the wheels of a car, or the propellers on a plane.
Quantum spin is a subject of its own, but I just wanted to bring this up here to prevent any confusion around protons spinning.
Additionally, and as a final note, quantum spin is like mass - it's an inherent property quantum particles.
This alone doesn't mean much in terms of a machine being able to image body tissue, but scientists then apply a radio-frequency, which is a type of electromagnetic radiation that you take advantage of everyday to use your phones, laptops televisions etc.
When protons are bombarded with this radiation, which is essentially a packet of energy, protons are shifted out of equilibrium and they start to spin against the flow of the magnetic field lines.
They can be turned upright to spin perpendicular to the magnetic field lines, or even toppled completely over to spin in the opposite direction.
Scientists then remove the radio frequency by turning the source off, which causes the protons to realign with the magnetic field, in the absence of this radio-frequency that was causing them to shift to a different direction.
During the realignment, protons release quantities of energy in the form of their own radio waves that can be detected by machinery, and used to produce a 3D image of the body.
While I've been generally referring to the protons in your body up until now, it's specifically the protons that make up the hydrogen atoms in every molecule of water in your body that are stimulated to release these radio-waves that are later detected.
And that's pretty much it!
The main advantage of an MRI over say an X-ray is that no harmful ionising radiation is used in the process.
X-rays are the second most energetic form of radiation, coming only before gamma rays, and hence they can cause a lot of damage to human cells if they're exposed to them for long enough, hence why you can only have a certain amount of X-rays per year.
MRI scans, on the other hand, only involve a magnetic field and a very weak form of radiation that you're likely exposed to every minute of every day, although that's a question in and of itself, and the reality is that radio waves still negatively interact with the human body, despite what technology firms might preach.
Thanks for reading, and I hope that you managed to learn at least 1 thing from this article!