What was the last?
Unclear; as with many things Doctor Who, it depends on how you define a "pure historical."
"Black Orchid", a Fifth Doctor story broadcast in 1982 and set in 1925, was the last story set in Earth's past (relative to broadcast date), that contained no science fiction elements (aside from the Doctor himself, obviously). However, "Black Orchid" doesn't depict actual events (not famous ones, anyway).
"The Highlanders", a Second Doctor story broadcast in 1966/7 and set in the late 1740s, was the last story to depict actual events (the Battle of Culloden) in Earth's past, with no science fiction elements
My personal favourite source for Doctor Who criticism, Philip Sandifer, argues in his analysis of "The Highlanders" that in a certain sense you should really consider "The Smugglers" to be the last true historical (link preserved from the original, but updated to point to the right page):
[T]his isn't the last historical, due largely to the fact that other than having no overt science fiction elements, nothing about it even faintly resembles historicals we've seen before. In terms of televised Doctor Who, The Smugglers was the last historical, and this is just a parody of the genre to reiterate after last time that the entire rulebook has been chucked out the window.
His reasoning is for complicated lit-crit reasons that I won't do justice to here, but one of his more accessible reasons is that "The Smugglers" is the last pure historical that takes its history seriously; "The Highlanders" is more of a romp, with the historical setting really just being a backdrop for Patrick Troughton to be hilarious1 for two hours.
So you can draw the line in any of a number of places, depending on what you consider to be a "true" historical
Why did they end?
Although reports from the time are hard to find on the Internet (and were a bit before my time anyway), most of the criticism I can find lays the blame on Innes Lloyd, the producer from 1966 to 1968, who had a noted distaste for the genre. In a (purported) 1980s interview with Lloyd, he argues that they simply weren't as popular:
We found that the historical stories weren't popular! 'The Highlanders' was the last one we did, and previous to that we'd run the very badly received cowboy one, 'The Gunfighters'. The problem, I thought, was that we had too many very good costume dramas on the BBC, especially at that family viewing slot. So we were really stepping into somebody else's territory. I wanted the kind of adventure stories you could relate to in everyday life, and I was looking for something as an alternative to the Daleks – which is why the Cybermen came about, and later the Yeti.
Slightly more substantial as a source, the BBC episode guide for "The Smugglers" quotes Doctor Who, the Television Companion, who argue against the scrapping of the pure historical but echo Lloyd's opinion of them:
To write [pure historicals] off simply on the basis that one or two were below par would be to make the same mistake that Innes Lloyd did when, in the light of critical comments such as those contained in the Audience Research Report on The Gunfighters, he assumed - rather conveniently, given that he himself disliked this type of story - that the historicals were generally unpopular.
In a 2001 interview with Michael Troughton (son of the late Patrick Troughton), published in Doctor Who Magazine, he reiterates that it was primarily a decision made by Lloyd and Sydney Newman, one of the show's creators:
Although The Highlanders was a catalyst for a new style of Doctor Who, it was, itself, the last of a dying breed - the historical story. Innes Lloyd and Sydney Newman had discussed with Dad that they thought a more science fiction-styled series would prove a greater success with audience and writers alike. My father had enthusiastically encouraged this direction, not only because it divorced him further from the William Harntell era, but because he was genuinely interested in exploring "real science in drama".
Doctor Who Magazine (306) "Michael Troughton's Memories Part One: Top of the Pops" 25 July 2001
However, Philip Sandifer makes two slightly different cases in a TARDIS Eruditorium post, essentially arguing that they died out of narrative necessity:
One style of historical, the package tour of genre tropes, had basically played itself out; "The Time Meddler" proved that these are vastly more fun when you can include some subtle scifi elements
The other style of historical, the more dramatic one about cultural differences, becomes really icky when you put the Doctor into a heroic role; I'll let Sandifer speak for himself here (link added by me):
If the Doctor is a sympathetic and likable character in part because of his commitment to fighting evil then we run into a huge problem when we put him in a historical setting. The Massacre is, for all its genius, the story where we can see this problem actually killing the genre before our eyes. The heart of the problem is one I said in that entry - Steven is right and the Doctor is wrong. It is clearly and unambiguously the case that slaughtering the Huguenots is wrong. Having the Doctor simply walk away from it saying that it happened so there's nothing he can do about it is only possible in that story because the Doctor has been so spectacularly diminished by the stories immediately preceding it. Under normal circumstances, watching the Doctor shrug his shoulders and walk away from vicious wrongdoing is... well... wrong.
[...]
The problem, in other words, is that there's something desperately unsatisfying about a crusader for good who will stop any travesty unless it happened on Earth prior to the year 1967.
1 For certain definitions of "hilarious", anyway