The game at the National Stadium in Warsaw was watched by a crowd of around 44,000 and marked the 20th time Legia have won the national Cup title.
The Warsaw team prevailed despite having a player sent off after just seven minutes.
The match went into penalties after neither team managed to score after 90 minutes of normal time and 30 minutes of extra time.
Legia goalkeeper Kacper Tobiasz, who saved a penalty from Raków's Mateusz Wdowiak, was named the man of the match, Poland's PAP news agency reported.
Legia are nine points behind Raków at the top of the Polish premiere league, whose winner will face off against the Warsaw side for the national Super Cup title later this year in a curtain-raiser to the next football season.
(gs)
Source: PAP, Polsat