European football's governing body said it had selected the two countries ahead of Italy and another joint bid from Croatia and Hungary to stage the finals.
The Poland and Ukraine bid received eight votes to Italy's four. Croatia and Hungary got none. It is the first time either country has been chosen to host a major tournament.
The European championship finals, held every four years, are second only to the World Cup in importance in the world of football. Greece are the current European champions after pulling off a surprise victory in Portugal in 2004.
Austria and Switzerland are co-hosting Euro 2008.
"There are 85 million people now waiting for this big football event," Polish FA chairman Michal Listkiewicz said after UEFA president Michel Platini had revealed the winner.
"The friendship between our nations has a very long history. This big tournament will be an important milestone in the history of our two Slavic nations."
His comments were echoed by Ukrainian football federation president Hryhory Surkis.
"This is a decisive day for our country. It will provide new opportunities for our country as it strives to integrate with Europe," he told Ukrainian television in Cardiff.
The decision of UEFA's Executive Committee to choose the Ukraine and Polandbid dashed the hopes of Italy, who had been slight favourites to be named host nation for a third time.
Polandand Ukraine's bid appeared to have been undermined on two fronts.
FIFAhad threatened to ban Poland from international competition after its government removed the country's football association from power in January after a scandal involving corrupt referees.
Theunstable political climate in Ukraine where a presidential decree dissolved parliament and called for a new election next month, also raised doubts.
Ina statement, Ukraine president Viktor Yushchenko said that the decision offered a great opportunity to both countries to host an "extraordinary" sporting event.
"Holding the 2012European championship will be a wonderful opportunity for Ukrainians and Poles to welcome the best representatives of Europe's soccer family and produce an extraordinary sporting event," he said.
"Ukraine and Poland will be able to show millions of fans the unforgettable charm of their cities and the history they have preserved so beautifully and put on a display of Slav hospitality and culture," added the pro-WesternYushchenko.
The projected Polish venues for the 2012tournament include Gdansk, Poznan, Warsaw and Wroclaw while the Ukrainian cities of Kiev, Donetsk, Dnipropetrovsk and Lviv would stage games.
Kiev's Olympic Stadium, used to host football at the 1980Moscow Olympics, is the proposed venue for the final.