Come up trumps
To complete something well or successfully, especially in circumstances in which it isn't expected.
'Come up trumps' is a variant of the older phrase 'turn up trumps', which has been in use since the early 17th century.
The word trump in this context is a corruption of triumph, which was the name of a card game, similar to whist, that was played in the 17th century. The preacher Hugh Latimer referred to it in his 1st Sermon on the Card, 1529:
"The game that wee wyll playe at, shall bee called the triumphe... Lette therefore euery Christian manne and woman playe at these cardes."
Encouraging card playing is hardly Christian orthodoxy these days, nor was it in 1529, but then Latimer was far from orthodox in his religious views - which resulted in him being burned at the stake.
Shakespeare used card playing imagery when alluding to the game in Anthony and Cleopatra, 1606. He says that "the queen, [Cleopatra] whose heart I thought I had" ... "now lost, she has pack'd cards with Caesar and false-play'd my glory unto an enemy's triumph."
In triumph, as in whist, the trump suit was selected at random by the 'cutting' of the deck. Trump cards temporarily outranked other cards. Selecting the right suit to match one's hand was an advantage in the game and so turning up trumps became synonymous with success. It was, and still is, bad form to cut the deck without first shuffling the cards. Robert Burton, in his The anatomy of melancholy, 1621, was outraged that:
"They turned up trumpe, before the Cards were shuffled."
By the 18th century turn up trumps had begun to be used in its figurative sense, that is, with no direct reference to card playing. It is recorded that way in Grose's Dictionary of the Vulgar Tongue, 1785:
"Something may turn up trumps, something lucky may happen."
Incidentally, Shakespeare was also the first to refer to a pack of cards as a deck - in Henry VI, Part III, 1592:
"But whiles he thought to steale the single Ten, The King was slyly finger'd from the Deck."
See other phrases and sayings from Shakespeare.