The education minister for Wales has resigned following a row over his defence of a school which faced closure under his own surplus places policy.
Leighton Andrews had been seen holding a banner in support of Pentre Primary School in his Rhondda constituency.
And First Minister Carwyn Jones failed to defend him from opposition claims he undermined his own policy.
Mr Jones had previously rebuked Mr Andrews for his actions in defending a local hospital from possible cuts.
In a letter to the first minister released on Tuesday afternoon, Mr Andrews said: "I feel I have no option but to offer you my resignation today.
"I regret that my commitment to my constituents may have led me to an apparent conflict which led to difficulty for the government."
Mr Jones accepted the resignation with "great regret".
He added: "I recognise very well that there is sometimes tension between the role of a government minister and the demands of a constituency assembly member.
"The ministerial code aims to define the boundaries between the two roles and, on this occasion, I believe those roles were confused."
Mr Andrews was photographed earlier this month holding a sign saying "Save Pentre Primary and our community".
The minister said he was standing up for his constituents as Rhondda's assembly member.
But Mr Andrews has repeatedly warned councils across Wales that they must close and amalgamate schools to deal with excess capacity.
He was also at the centre of a political row over health two weeks ago when he was rebuked by Mr Jones for using the Labour party's name to oppose potential cuts to specialist accident and emergency services at the Royal Glamorgan hospital in Llantrisant which serves his constituency.
Welsh Conservatives leader Andrew RT Davies said the resignation was "inevitable" and that Mr Andrews' position had become "untenable".
He added: "His resignation will now enable him to articulate these concerns from the backbenches - however they don't change the damaging policies of Carwyn Jones' government, in particular in health and education."
Welsh Liberal Democrats leader Kirsty Williams added: "It was quite clear in first minister's questions today that Carwyn Jones was not willing to defend the actions of the education minister but instead was willing to defend the policy of surplus places.
"And I think that was a clear indication that the education minister could not carry on in this way."
Plaid Cymru education spokesman Simon Thomas said: "This is the correct decision to take when collective cabinet responsibility has been abdicated and you find yourself arguing against your own policies."
Former Labour Welsh Secretary Peter Hain described Mr Andrews' resignation as "catastrophic for Welsh Labour".
In a message posted on Twitter Mr Hain described him as an "incredibly able and dynamic Education Minister [who] refused to accept low standards".
Shadow Welsh Secretary Owen Smith praised Mr Andrews as "one of the most effective and committed ministers" in the Welsh government who would continue to represent his Rhondda constituents "robustly and passionately".
Labour's Rhondda MP Chris Bryant, seen at the same school and hospital protests, said: "I think there will be a huge cheer of support in the valleys tonight for Leighton Andrews."
The row began after Rhondda Cynon Taf council (RCT) completed consultation on closing Pentre Primary School which has just 73 pupils, despite having room for 202.
The council issued a statement saying every council in Wales was "under a clear direction" from the Welsh government to tackle the matter of surplus places within its schools.
The authority confirmed Pentre had the highest percentage of surplus places - 64% - of any school within Rhondda and so had to be considered for closure.
Mr Andrews wrote a detailed objection to the council's plans for Pentre on the grounds that Welsh government guidance had not been properly followed by the Labour-run council.
The National Union of Teachers said Mr Andrews' resignation came at a time of great upheaval in the sector, while the National Association of Head Teachers said he had made a powerful contribution to education policy in Wales.
The Association of Teachers and Lecturers said they had not always seen eye to eye with Mr Andrews, but did not doubt his commitment to improving school performance, calling for a "credible, and more importantly, competent" successor.