On 28 March 1193 Richard was brought to Speyer and handed over to Henry VI, Holy Roman Emperor, who imprisoned him in Trifels Castle. Henry VI was aggrieved by the support the Plantagenets had given to the family of Henry the Lion and by Richard's recognition of Tancred in Sicily. Henry VI needed money to raise an army and assert his rights over southern Italy and continued to hold Richard for ransom.  In response, Pope Celestine III excommunicated Henry VI, as he had Duke Leopold, for the continued wrongful imprisonment of Richard. Richard famously refused to show deference to the emperor and declared to him, "I am born of a rank which recognises no superior but God". Despite his complaints, the conditions of his captivity were not severe. The emperor demanded that 150,000 marks  be delivered to him before he would release the king, the same amount raised by the Saladin tithe only a few years earlier, and 2-3 times the annual income for the English Crown under Richard. Richard's mother, Eleanor of Aquitaine, worked to raise the ransom. Both clergy and laymen were taxed for a quarter of the value of their property, the gold and silver treasures of the churches were confiscated, and money was raised from the scutage and the carucage taxes. At the same time, John, Richard's brother, and King Philip of France offered 80,000 marks for the Emperor to hold Richard prisoner until Michaelmas 1194. The emperor turned down the offer. The money to rescue the King was transferred to Germany by the emperor's ambassadors, but "at the king's peril" , and finally, on 4 February 1194 Richard was released. Philip sent a message to John: "Look to yourself; the devil is loose".

Which happened first, the Pope excommunicating Henry VI or the emperor imprisoning Richard?
Emperor, who imprisoned him