You do it with Target Display Mode. You're right on the cusp of compatibility here! TDM only works on <2014 iMacs (so it will work on yours). According to Apple documentation, these are the requirements:
If the iMac has Thunderbolt, then the iMac can only be used as a display for other Macs and you need to use a Thunderbolt 2 cable to make a Thunderbolt connection.
If the Mac you want to connect to the iMac has Thunderbolt 3 or Thunderbolt 4, then you need to connect the Thunderbolt 2 cable with an Apple Thunderbolt 3 to Thunderbolt 2 Adapter.
As an Amazon Associate we earn from qualifying purchases.