LISBON—Running out of money and paralyzed by a political crisis, Portugal said Wednesday it would ask the European Union for a financial bailout—setting up a crucial test of the bloc's emboldened efforts to contain its sovereign-debt crisis.

Portugal is the third nation in the 17-member euro zone to turn to its peers for help, and one that has long been seen as a firewall between small economies whose bailouts are painful but manageable and large economies—like Spain—whose infection would set the crisis on a far darker course.

It has appeared inevitable for weeks. Portugal has struggled to raise cash from wary financial markets, and its persistent deficits are draining state coffers.

Politics are at a standstill: Two weeks ago, Mr. Sócrates's government collapsed after parliament rejected his latest bid to rein in Portugal's budget. Mr. Sócrates had adamantly refused to countenance a bailout. Wednesday night, he said he had no choice.