The back of the iMac you have should have a port that looks like these two ports here:

As long as both your MacBook and iMac have these ports, you can take the machine that doesn't boot all the way and boot it with the 'T' key.
If it gets the logo of thunderbolt booting, you can connect a cable like
Apple Thunderbolt Cable (0.5 m) - White - Apple
and link the two machines.
With any luck, the non-responsive machine's hard drive will appear on the desktop of the responsive machine.
If it doesn't appear, and you upgraded the non-responsive machine with HIgh Sierra or later, you'll need the responsive machine to be upgraded to High Sierra first before you connect the two machines.
APFS is the new format all solid state drives take in High Sierra and later.
If both machines are running less than HIgh Sierra and connecting via target mode does not show the other machine under Go menu -> Computer in the Finder, then it is possible the target machine's hard drive needs a data recovery expert to look at the drive.
http://www.drivesavers.com is expensive, but they have been known to rescue data even from dying hard drives.
This is why it is so important you backup your data before this kind of conundrum happens.
If you are able to get the data, copy it to an external hard drive separate from the non-responsive computer.
Backup now, or forever hold your peace - … - Apple Community
The boot system itself may be munged, but you may still be able to recover the data.
I would not upgrade past Mojave, as beyond that all applications have to be upgraded to 64 bit. And only do so once both machines have been backed up. If neither machine has been updated beyond Sierra, don't until you verify both can be. A late 2012 machine can be. Without knowing the age of your MacBook, I can't say what can or can't be done.