Ramirez had long been seen as a target of Maduro's aggressive push to consolidate power in the run-up to next year's presidential elections in the crisis-wracked South American country.
"I have resigned from my role as ambassador at the request of the president of the republic ... I have been removed for my opinions and I will remain, whatever happens, loyal to Comandante Chavez!" Ramirez wrote in a resignation letter posted on Twitter.
The note, addressed to Foreign Minister Jorge Arreaza, indicated he had been expecting the move.
"This decision is in line with the agreements reached in our conversation once we received the instruction of the president of the republic," he wrote.
Former foreign minister Samuel Moncada was named as Ramirez's replacement.
Meanwhile, chief prosecutor Tarek William Saab denied the existence of rifts within the Socialist Party, and said the only fight is against "those who have harmed the country".
Ramirez had previously been head of Venezuela's state oil giant, PDVSA, for a decade from 2004-14.
Ramirez loyalists, including Eulogio Del Pino and Nelson Martinez, have recently been arrested and removed from key posts - the former as oil minister and the latter as PDVSA chief - in what analysts see as an ongoing purge.
They are the highest-ranking officials to be arrested in the anti-corruption moves at PDVSA, which accounts for almost all the country's income.
Oil minister Manuel Quevedo, a former general installed to replace both men, told reporters at an OPEC meeting last week that Venezuela's oil production was being sabotaged as a prelude to a coup.
The South American country, teetering on the brink of a full-blown default on its massive debt, has the world's biggest reserves of oil.
But because of endemic corruption and a chronic lack of investment, the OPEC member's oil production is falling sharply.
Annual output is around 1.9 million barrels per day, having slumped more than 23% between January 2016 and October this year.