After enjoying the favours of Onaelia, niece to the duke of Medina, the Spanish king repudiates her and her son, Sebastian, making Paulina, daughter of the duke of Florence, his queen. On hearing this, the noble soldier Balthazar works on the conscience of the king to take back Onaelia. Despite the threat of civil war, the king refuses. Count Malatesta proposes to the queen that she pretend to be pregnant, to sound the hearts of the Spanish people. Roderigo, Lopez, and Valasco, dons of Spain, rally to the cause of their majesties against the duke of Medina's faction. Angered at her rival, the queen proposes to Balthazar the murder of Onaelia and her son, to which he pretends to acquiesce after receiving the king's command. But, loyal to Onaelia, Balthazar announces these plots to Medina, who disguises himself as a French doctor to gain access to the king.
When the disguised Medina speaks to the king, he becomes convinced of the legitimacy of the king's plot to murder his niece as well as Balthazar's loyalty. To appease the rebellious faction, the king proposes a marriage between Onaelia and Cockadillio, a courtier, an offer which is accepted. The queen and Malateste again confer, deciding to poison Onaelia. During the marriage ceremony, the king takes up the poisoned cup meant for Onaelia, to the queen's and Malateste's consternation. While the king is drinking, Malateste admits their crime and is stabbed to death by the faction. While dying, the king passes the crown to Sebastian and commands that the queen be sent back to Florence with treble dowry. Onaelia and Balthazar are appointed to protect Sebastian in his youth.

Question: When was Sebastian given the Spanish crown?
Answer: as the king was dying
Alternative answer: When the dying king passed on his crown to him.