The protocol that lets two different blockchains share the same consensus mechanism as well as hash functions to mine together, is called merged mining. A high level of security is maintained in the process without compromising the performance.
Merged mining came into existence in 2014 when the Auxiliary Proof of Work was released. This technology lets the work done in one proof of work-based blockchain be used as the proof of work on another blockchain for mining blocks. This consensus first got implement on Bitcoin and Namecoin. This became feasible due to the fact that both the blockchain networks used the SHA-256 mining algorithm which is one of the important factors for this process to take place.
In merged mining, one blockchain network serves as the primary network while the other network behaves as the auxiliary network. There exists one network where all the mining is done while there is another where the proof of work gets accepted for block mining without actually performing the work on that blockchain. The primary blockchain network must allow the inclusion of arbitrary data in the headers of the mined block. On the other hand, the auxiliary network should provide a verification procedure demonstrating that an effort was made by the miners in the parent blockchain network.