Those who achieve great things in history have always been driven.
In Tyrion's case, his father's hatred and the world's disdain has always been his driving force. Given an actual education and opportunity due to his father's well-hidden love (that is in many ways so harsh it is abuse), as well as the intelligence that led his family to the top of the Realm, he is a man primed to 'rise to the top' - given an opportunity, he'll set the world on fire (as shown on the Blackwater).
He's also a man who has lost everything. Betrayed by those he loved, toughened by years of disdain to not simply crumple under those circumstances, it's the kind of kick up the rear that tells those intelligent and driven but just a little bit naive, that they need to start breaking rules to get what they want.
In the story, Tyrion has always been the innocent - seeking a greater good where those more cynical (including his entire family) see only the greed of Man. As a noble, he can see that his one chance to still do good is to find someone who is not afraid of his family's wrath, and who is yet in precarious enough position that his advice (as an intelligent and fully-trained noble - nobles' work was with words and mind, not the body, the 'noble knight' is actually a failure) is useful. Finding an honest-to-goodness Targaryen heir with dragons over the sea is basically the greatest sign the old gods could have given him that they have his back. If he can make himself useful to her (and given his knowledge and skill, he really can), she is his ticket back into the kingdom, and perhaps, a new golden age for Westeros.
It pretty much appeals to every single one of his desires. So much so it probably seems too good to be true.
And in the converse, why should Daenerys agree? Because Barristan's old, everyone else is an effete slaver or uneducated, Mormont is a pompous failure, and she is untrained and winging it on pure charisma (with her own share of bad decisions). Someone like Tyrion, intelligent, devious, noble-trained, with reasons to see her succeed and none of the arrogance or pride to betray her? Makes you think perhaps Valyrian magic isn't a myth.